R Markdown

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

Including Plots

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\\09. Non Ortho_WHITE SPOTS LESION\\09. SURVEY TABLE ON THE CONDITION OF WHITE SPOTS ON TEETH.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
# 1. MÃ HÓA VÀ GHI ĐÈ TRỰC TIẾP LÊN BẢNG GỐC (df)
df <- df %>%
  mutate(
    # --- 1. NHÓM DÙNG CHUNG THANG ĐO YES/NO (0 = No, 1 = Yes) ---
    across(
      c(B1, B2, B3, B4, B5, 
        C3, C4, C5, 
        D3, D14A, D14B, D14C, D15A, D15B, D17, 
        E9A, E9B, E9C, E9D),
      ~ factor(., levels = c(0, 1), labels = c("No", "Yes"))
    ),
    
    # --- 2. NHÓM TẦN SUẤT SỬ DỤNG CÔNG CỤ (E13 - E17) ---
    across(
      c(E13, E14, E15, E16, E17),
      ~ factor(., levels = c(0, 1, 2, 3), 
               labels = c("Never", "Occasionally", "Once a day", "2-3 times a day"))
    ),
    
    # --- 3. CÁC BIẾN CÓ THANG ĐO RIÊNG BIỆT ---
    Gender = factor(Gender, levels = c(0, 1), labels = c("Male", "Female")),
    
    # Nhóm C
    C2 = factor(C2, levels = c(0, 1, 2), 
                labels = c("I am not sure", "Yes, I have seen white spots before", "No, I have not noticed any white spots")),
    
    # Nhóm D (Kiến thức/Nhận thức)
    D1 = factor(D1, levels = c(0, 1, 2, 3), 
                labels = c("Pre-caries lesions", "Loss of mineralization on the tooth enamel surface", "Only appears in anterior teeth", "A and B are true")),
    D2 = factor(D2, levels = c(0, 1, 2, 3), 
                labels = c("Not good oral hygiene", "Fluoride infected", "Eat lots of acidic foods", "All")),
    D4 = factor(D4, levels = c(0, 1, 2), 
                labels = c("No", "Yes", "I don't remember / I haven't paid attention")),
    D5 = factor(D5, levels = c(0, 1, 2, 3), 
                labels = c("From a dentist", "From people who have undergone treatment", "From the internet, etc.", "Other")),
    D6 = factor(D6, levels = c(0, 1, 2, 3), 
                labels = c("Soft debris on teeth", "Tooth discoloration", "Hard deposits on teeth", "I don't know")),
    D7 = factor(D7, levels = c(0, 1, 2, 3), 
                labels = c("Soft debris on teeth", "Tooth discoloration", "Hard deposits on teeth", "I don't know")),
    D8 = factor(D8, levels = c(0, 1, 2, 3), 
                labels = c("Gum inflammation", "Tooth discoloration", "Tooth decay", "I don't know")),
    D9 = factor(D9, levels = c(0, 1, 2, 3), 
                labels = c("Clean and shiny teeth", "Prevention of cavities and gum diseases", "Reduced dental care costs", "I don't know")),
    D10 = factor(D10, levels = c(0, 1, 2), 
                 labels = c("No", "Yes", "I don't know")),
    D11 = factor(D11, levels = c(0, 1, 2, 3), 
                 labels = c("Every 1-3 months", "Every 4-6 months", "Every 7-12 months", "More than 1 year")),
    D12 = factor(D12, levels = c(0, 1, 2, 3), 
                 labels = c("I don't know", "Every 6 months", "Once a year", "Every 2 years")),
    D13 = factor(D13, levels = c(0, 1, 2, 3), 
                 labels = c("1 tooth", "2 teeth", "3 teeth", "4 teeth")),
    D16 = factor(D16, levels = c(0, 1), 
                 labels = c("Low (indistinct white spot borders)", "High (clearly defined white spot borders)")),
    
    # Nhóm E (Thói quen vệ sinh răng miệng)
    E1 = factor(E1, levels = c(0, 1, 2, 3), 
                labels = c("Not regularly", "Once a day", "Twice a day", "Three times a day")),
    E2 = factor(E2, levels = c(0, 1, 2, 3), 
                labels = c("Less than 1 minute", "1 - 3 minutes", "More than 3 minutes", "Until it feels clean")),
    E3 = factor(E3, levels = c(0, 1, 2, 3), 
                labels = c("Soft-bristled regular toothbrush", "Hard-bristled regular toothbrush", "Orthodontic toothbrush", "Any toothbrush")),
    E4 = factor(E4, levels = c(0, 1, 2, 3), 
                labels = c("Every 3-6 months", "When bristles wear out", "When the handle breaks", "When a new design is available")),
    E5 = factor(E5, levels = c(0, 1, 2), 
                labels = c("No", "Yes", "Not sure")),
    E6 = factor(E6, levels = c(0, 1, 2, 3), 
                labels = c("Vertically", "Horizontally", "Circular motion", "Other")),
    E7 = factor(E7, levels = c(0, 1, 2), 
                labels = c("Right hand", "Left hand", "Both hands")),
    E8 = factor(E8, levels = c(0, 1, 2), 
                labels = c("None", "A little", "A lot")),
    E10 = factor(E10, levels = c(0, 1, 2, 3), 
                 labels = c("Horizontal brushing", "Bass/Modified Bass", "Charter", "Not sure")),
    E18 = factor(E18, levels = c(0, 1, 2, 3), 
                 labels = c("3 months/time", "6 months/time", "6-12 months/time", ">12 months/time")),
    E19 = factor(E19, levels = c(0, 1, 2, 3), 
                 labels = c("Never", "Rarely", "Occasionally (1-2 times a day)", "Frequently (3+ times a day)")),
    E20 = factor(E20, levels = c(0, 1, 2, 3), 
                 labels = c("Never", "Occasionally", "1-5 cigarettes per day", "More than 5 cigarettes per day")),
    E21 = factor(E21, levels = c(0, 1, 2, 3), 
                 labels = c("Never", "Occasionally", "Weekly", "Daily"))
  )

# 2. GẮN NHÃN MÔ TẢ (LABELS) CHUẨN XÁC THEO HÌNH ẢNH
df <- df %>%
  set_variable_labels(
    Gender = "Gender",
    B1 = "Do you have any systemic diseases?",
    B2 = "Are you currently taking any medication that reduces saliva production?",
    B3 = "Do you experience dry mouth?",
    B4 = "Do you have difficulty swallowing?",
    B5 = "Do you frequently feel thirsty?",
    
    C2 = "Have you discovered white spots on your teeth before?",
    C3 = "Does plaque exist on the surface of your teeth?",
    C4 = "Do you have bleeding gums?",
    C5 = "Do you experience bad breath?",
    
    D1 = "In your opinion, what are the white spots?",
    D2 = "What are the causes of white spots?",
    D3 = "Have you heard of white spots on teeth before?",
    D4 = "Have you ever researched prevention methods for white spots?",
    D5 = "Where did you learn about prevention methods?",
    D6 = "What do you think dental plaque is?",
    D7 = "What do you think calculus is?",
    D8 = "What are the consequences of plaque accumulation?",
    D9 = "What are the benefits of brushing your teeth?",
    D10 = "Does fluoride help strengthen teeth?",
    D11 = "How often should you replace your toothbrush",
    D12 = "How often should you visit the dentist for a check-up?",
    D13 = "Number of Teeth with White Spots",
    D14A = "Location of White Spots on the Tooth Surface: Upper third (cervical)",
    D14B = "Location of White Spots on the Tooth Surface: Middle third",
    D14C = "Location of White Spots on the Tooth Surface: Lower third (toward the incisal) edge/occlusal surface",
    D15A = "Color of White Spots (Multiple choices): White",
    D15B = "Color of White Spots (Multiple choices): Yellow/Orange",
    D16 = "Contrast between White Spots and tooth surface",
    D17 = "If you noticed white spots on your teeth as described in the image, would you seek treatment?",
    
    E1 = "How often do you brush your teeth per day?",
    E2 = "How long do you brush your teeth each time",
    E3 = "What type of toothbrush do you use?",
    E4 = "When do you replace your toothbrush?",
    E5 = "Does your toothpaste contain fluoride?",
    E6 = "How do you brush your teeth?",
    E7 = "Which hand do you use to brush your teeth?",
    E8 = "How much pressure do you apply when brushing?",
    E9A = "When do you brush your teeth? (Multiple choices): In the morning",
    E9B = "When do you brush your teeth? (Multiple choices): After lunch",
    E9C = "When do you brush your teeth? (Multiple choices): Before bedtime",
    E9D = "When do you brush your teeth? (Multiple choices): Other times",
    E10 = "Brushing technique",
    E13 = "Water flosser",
    E14 = "Electric toothbrush",
    E15 = "Dental floss",
    E16 = "Interdental brush",
    E17 = "Toothpick",
    E18 = "How often do you go to the dentist?",
    E19 = "Do you snack between meals?",
    E20 = "Do you smoke?",
    E21 = "How often do you consume alcohol in the past 12 months?"
  )
library(writexl)
## Warning: package 'writexl' was built under R version 4.5.3
# 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)\\9\\09. SURVEY TABLE ON THE CONDITION OF WHITE SPOTS ON TEETH.xlsx")