This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
df = read.csv2("D:\\TAM DAN NON-ORTHO\\10. Non ortho_EXAMINATION OF TEETH AND PERIDONTICAL CONDITION\\10.1 CONDITION OF TEETH _ DMFT\\10.1 CONDITION OF TEETH _ DMFT.csv")
library(lessR)
## Warning: package 'lessR' was built under R version 4.5.2
##
## lessR 4.5 feedback: gerbing@pdx.edu
## --------------------------------------------------------------
## > d <- Read("") Read data file, many formats available, e.g., Excel
## d is the default data frame, data= in analysis routines optional
##
## Many examples of reading, writing, and manipulating data, graphics,
## testing means and proportions, regression, factor analysis,
## customization, forecasting, and aggregation to pivot tables.
## Enter: browseVignettes("lessR")
##
## View lessR updates, now including modern time series forecasting
## and many, new Plotly interactive visualizations output. Most
## visualization functions are now reorganized to three functions:
## Chart(): type="bar", "pie", "radar", "bubble", "treemap", "icicle"
## X(): type="histogram", "density", "vbs" and more
## XY(): type="scatter" for a scatterplot, or "contour", "smooth"
## Most previous function calls still work, such as:
## BarChart(), Histogram, and Plot().
## Enter: news(package="lessR"), or ?Chart, ?X, or ?XY
## There is also Flows() for Sankey flow diagrams, see ?Flows
##
## Interactive data analysis for constructing visualizations.
## Enter: interact()
library(labelled)
## Warning: package 'labelled' was built under R version 4.5.3
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:lessR':
##
## order_by, recode, rename
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(writexl)
## Warning: package 'writexl' was built under R version 4.5.3
# 1. MÃ HÓA VÀ GHI ĐÈ TRỰC TIẾP LÊN BẢNG GỐC (df)
df <- df %>%
mutate(
# --- ĐÁNH GIÁ TÌNH TRẠNG 32 RĂNG (Sơ đồ răng A11 -> A48) ---
across(
c(A11, A12, A13, A14, A15, A16, A17, A18, # Hàm trên bên phải
A21, A22, A23, A24, A25, A26, A27, A28, # Hàm trên bên trái
A31, A32, A33, A34, A35, A36, A37, A38, # Hàm dưới bên trái
A41, A42, A43, A44, A45, A46, A47, A48), # Hàm dưới bên phải
~ factor(., levels = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9),
labels = c("Normal",
"Tooth decay",
"Filled, with decay",
"Filled, no decay",
"Missing due to decay",
"Missing for another reason",
"Fissure sealant",
"Fix dental prosthesis/crown, abutment, veneer",
"Unerupted",
"Not recorded"))
)
)
# 2. GẮN NHÃN MÔ TẢ (LABELS) CHO TỪNG RĂNG
# Lệnh này giúp khi xuất Excel hoặc vẽ biểu đồ, bạn sẽ biết rõ biến nào là răng nào
df <- df %>%
set_variable_labels(
A11 = "Tooth status 11 (Upper right central incisor)",
A12 = "Tooth status 12 (Upper right lateral incisor)",
A13 = "Tooth status 13 (Upper right canine)",
A14 = "Tooth status 14 (Upper right first premolar)",
A15 = "Tooth status 15 (Upper right second premolar)",
A16 = "Tooth status 16 (Upper right first molar)",
A17 = "Tooth status 17 (Upper right second molar)",
A18 = "Tooth status 18 (Upper right third molar)",
A21 = "Tooth status 21 (Upper left central incisor)",
A22 = "Tooth status 22 (Upper left lateral incisor)",
A23 = "Tooth status 23 (Upper left canine)",
A24 = "Tooth status 24 (Upper left first premolar)",
A25 = "Tooth status 25 (Upper left second premolar)",
A26 = "Tooth status 26 (Upper left first molar)",
A27 = "Tooth status 27 (Upper left second molar)",
A28 = "Tooth status 28 (Upper left third molar)",
A31 = "Tooth status 31 (Lower left central incisor)",
A32 = "Tooth status 32 (Lower left lateral incisor)",
A33 = "Tooth status 33 (Lower left canine)",
A34 = "Tooth status 34 (Lower left first premolar)",
A35 = "Tooth status 35 (Lower left second premolar)",
A36 = "Tooth status 36 (Lower left first molar)",
A37 = "Tooth status 37 (Lower left second molar)",
A38 = "Tooth status 38 (Lower left third molar)",
A41 = "Tooth status 41 (Lower right central incisor)",
A42 = "Tooth status 42 (Lower right lateral incisor)",
A43 = "Tooth status 43 (Lower right canine)",
A44 = "Tooth status 44 (Lower right first premolar)",
A45 = "Tooth status 45 (Lower right second premolar)",
A46 = "Tooth status 46 (Lower right first molar)",
A47 = "Tooth status 47 (Lower right second molar)",
A48 = "Tooth status 48 (Lower right third molar)"
)
# Tạo một bảng copy tạm thời để đổi tên tiêu đề
df_export <- df %>%
# Lệnh này biến toàn bộ các "Nhãn dài" thành tên cột thực sự
setNames(var_label(., unlist = TRUE))
# Sau đó xuất cái bảng tạm này ra Excel
write_xlsx(df_export, "D:\\TAM DAN - NON ORTHO (NEW)\\10.1\\10.1 CONDITION OF TEETH _ DMFT.xlsx")