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\\07. ENG_BRUXISM SCREENER\\07. BRUXISM SCREENER – BRUXSCREEN.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(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(labelled)
## Warning: package 'labelled' 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(
# --- GENDER ---
Gender = factor(Gender, levels = c(0, 1), labels = c("Male", "Female")),
# --- NHÓM Q1 & Q2: BRUXISM & JAW SYMPTOMS ---
# Gộp toàn bộ nhóm thói quen và triệu chứng vì dùng chung thang đo (0-4 và 88)
across(
c(Q1a, Q1b, Q1c, Q1d, Q1e, Q1f,
Q2a1, Q2a2, Q2a3, Q2a4, Q2a5, Q2a6, Q2a7, Q2a8, Q2a9, Q2a10, Q2a11, Q2a12,
Q2b1, Q2b2),
~ factor(., levels = c(0, 1, 2, 3, 4, 88),
labels = c("Never", "Sometimes", "Regularly", "Often", "Always", "Don't know"))
),
# --- NHÓM C1 & C2: CLINICAL ASSESSMENT ---
across(
c(C1a, C1b, C2a, C2b, C2c),
~ factor(., levels = c(0, 1), labels = c("Absent", "Present"))
),
# --- C3a: OCCLUSAL/INCISAL WEAR (Mòn mặt nhai/rìa cắn) ---
across(
c(C3aP1, C3aP2, C3aP3, C3aP4, C3aP5, C3aP6),
~ factor(., levels = c(0, 1, 2, 3, 4),
labels = c("No visible wear", "Visible wear within the enamel",
"Visible wear with dentin exposure and loss of clinical crown height of ≤1/3",
"Loss of crown height >1/3 but <2/3", "Loss of crown height ≥2/3"))
),
# --- C3b: PALATAL WEAR (Mòn mặt trong) ---
C3bP2 = factor(C3bP2, levels = c(0, 1, 2),
labels = c("No visible wear", "Wear confined to the enamel", "Wear into the dentine")),
# --- C3c & C3d: WEAR CAUSE & HARD TISSUE CONDITION ---
across(
c(C3c1, C3c2, C3c3),
~ factor(., levels = c(0, 1), labels = c("No", "Yes"))
),
across(
c(C3d1, C3d2),
~ factor(., levels = c(0, 1), labels = c("No", "Have, position"))
)
)
# 2. GẮN NHÃN MÔ TẢ (LABELS) CHO TẤT CẢ CÁC BIẾN
df <- df %>%
set_variable_labels(
Gender = "Gender",
# Bruxism (Thói quen nghiến/siết răng)
Q1a = "Clench your teeth during sleep?",
Q1b = "Grind your teeth during sleep?",
Q1c = "Clench your teeth while awake?",
Q1d = "Grind your teeth while awake?",
Q1e = "Lightly press, touch, or hold teeth together while awake other than while eating?",
Q1f = "Firmly hold, tighten, or tense muscles while awake without clenching or bringing teeth together?",
# Jaw Symptoms (Triệu chứng hàm)
Q2a1 = "Upon awakening: PAIN",
Q2a2 = "Upon awakening: UNPLEASANTNESS",
Q2a3 = "Upon awakening: SENSITIVITY",
Q2a4 = "Upon awakening: TIREDNESS",
Q2a5 = "Upon awakening: TENSION",
Q2a6 = "Upon awakening: STIFFNESS",
Q2a7 = "Other times: PAIN",
Q2a8 = "Other times: UNPLEASANTNESS",
Q2a9 = "Other times: SENSITIVITY",
Q2a10 = "Other times: TIREDNESS",
Q2a11 = "Other times: TENSION",
Q2a12 = "Other times: STIFFNESS",
Q2b1 = "Jaw lock: During meals",
Q2b2 = "Jaw lock: Any other time",
# Clinical Assessment (Đánh giá lâm sàng)
C1a = "Extra-oral inspection a",
C1b = "Extra-oral inspection b",
C2a = "Intra-oral inspection of non-dental tissues a",
C2b = "Intra-oral inspection of non-dental tissues b",
C2c = "Intra-oral inspection of non-dental tissues c",
C3aP1 = "Occlusal/incisal wear P1",
C3aP2 = "Occlusal/incisal wear P2",
C3aP3 = "Occlusal/incisal wear P3",
C3aP4 = "Occlusal/incisal wear P4",
C3aP5 = "Occlusal/incisal wear P5",
C3aP6 = "Occlusal/incisal wear P6",
C3bP2 = "Palatal wear in sextant 2",
C3c1 = "Wear cause: Mainly mechanical",
C3c2 = "Wear cause: Mainly chemical",
C3c3 = "Wear cause: Both mechanical and chemical",
C3d1 = "Enamel Cracks in teeth",
C3d2 = "Non-carious cervical lesions"
)
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)\\7\\07. BRUXISM SCREENER – BRUXSCREEN.xlsx")