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\\06. Non ortho_OCCLUSION\\06.3 Non ortho_ICON & OCCLUSION & OMES\\06.3 Non ortho_ICON_OCCLUSION_OMES.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 ĐÈ LÊN BIẾN GỐC (ĐÃ BỎ DẤU CHẤM)
df <- df %>%
mutate(
# --- GENDER ---
Gender = factor(Gender, levels = c(0, 1), labels = c("Male", "Female")),
# --- KHOẢNG TRỐNG / CHEN CHÚC (CROWDING) ---
across(
c(ICQ38_Score, ICQ39_Score),
~ factor(., levels = c(0, 1, 2, 3, 4, 5, 888),
labels = c("<2mm", "2-5mm", "5-9mm", "9-13mm", "13-17mm", ">17mm", "none"))
),
# --- CẮN HỞ (OPEN BITE) ---
eQ13 = factor(eQ13, levels = c(0, 1, 2, 3, 4, 888),
labels = c("confrontation", "<1", "1-2mm", "2-4mm", "4+mm", "none")),
# --- CẮN PHỦ (OVERBITE) ---
ICQ40 = factor(ICQ40, levels = c(0, 1, 2, 3, 888),
labels = c("<1/3", "1/3 - 2/3", "2/3 to the end of the teeth", "Cover all teeth", "none")),
# --- PHÂN ĐOẠN RĂNG SAU (BUCCAL SEGMENT) ---
ICQ41 = factor(ICQ41, levels = c(0, 1, 2),
labels = c("Class I,II,III", "Any, none confrontation", "Confrontation")),
# --- PHÂN LOẠI ANGLE (ANGLE CLASSIFICATION) ---
across(
c(Q42, Q43),
~ factor(., levels = c(0, 1, 2, 3, 4, 5),
labels = c("0", "Class I", "Class II div 1", "Class II div 2", "Class III", "NA"))
),
# --- HÌNH DÁNG HÁ MIỆNG (Q47 SHAPE) ---
Q47Shape = factor(Q47Shape, levels = c(0, 1, 2, 3, 4),
labels = c("Normal", "Zigzag on the right", "Zigzag on the left", "Lean to the right", "Lean to the left")),
# =====================================================================
# --- NHÓM CÂU HỎI YES/NO KHỔNG LỒ (Crossbite, Midline, Khám TMJ...) ---
# =====================================================================
across(
c(cQ10, Q44, Q45, Q46, Torus,
Q47R1, Q47R2, Q47R3,
Q47L1, Q47L2, Q47L3,
Q49R1, Q49R2, Q49R3, Q49R4, Q49R5,
Q49L1, Q49L2, Q49L3, Q49L4, Q49L5,
Q50R1, Q50R2, Q50R3,
Q50L1, Q50L2, Q50L3,
Q51R1, Q51R2, Q51R3, Q51R4, Q51R5, Q51R6, Q51R7,
Q51L1, Q51L2, Q51L3, Q51L4, Q51L5, Q51L6, Q51L7),
~ factor(., levels = c(0, 1), labels = c("None", "Have"))
)
)
# 2. GẮN NHÃN MÔ TẢ (LABELS) CHO TẤT CẢ BIẾN
df <- df %>%
set_variable_labels(
Gender = "Gender",
ICQ38 = "Upper arch crowding (mm)",
ICQ38_Score = "Upper arch crowding",
ICQ39 = "Lower arch crowding (mm)",
ICQ39_Score = "Lower arch crowding",
cQ10 = "Crossbite",
eQ13 = "Open bite",
ICQ40 = "Overbite",
ICQ41 = "Buccal segment A-P",
Q42 = "Angle classification (Right)",
Q43 = "Angle classification (Left)",
Q44 = "Midline shift",
Q45 = "To right side",
Q45_Maxi = "Maxillary arch (mm)",
Q45_Mandi = "Mandibular arch (mm)",
Q46 = "To left side",
Q46_Maxi = "Maxillary arch (mm)",
Q46_Mandi = "Mandibular arch (mm)",
Torus = "Mandibular torus",
FA20 = "The Mew Indicator line (From the incisal edge of the tooth #21 to the tip of the nose) (mm)",
# Nhóm Q47
Q47R1 = "Normal (Opening Right)",
Q47R2 = "Pain (Opening Right)",
Q47R3 = "Midline deflection (Opening Right)",
Q47L1 = "Normal (Opening Left)",
Q47L2 = "Pain (Opening Left)",
Q47L3 = "Midline deflection (Opening Left)",
Q47Shape = "Shape",
# Nhóm Q49
Q49R1 = "Normal (Q49 Right)",
Q49R2 = "Pain (Q49 Right)",
Q49R3 = "Midline deflection (Q49 Right)",
Q49R4 = "Obstruct working side (Q49 Right)",
Q49R5 = "None obstruct working side (Q49 Right)",
Q49L1 = "Normal (Q49 Left)",
Q49L2 = "Pain (Q49 Left)",
Q49L3 = "Midline deflection (Q49 Left)",
Q49L4 = "Obstruct working side (Q49 Left)",
Q49L5 = "None obstruct working side (Q49 Left)",
# Nhóm Q50
Q50R1 = "Normal (Q50 Right)",
Q50R2 = "Pain (Q50 Right)",
Q50R3 = "Midline deflection (Q50 Right)",
Q50L1 = "Normal (Q50 Left)",
Q50L2 = "Pain (Q50 Left)",
Q50L3 = "Midline deflection (Q50 Left)",
# Nhóm Q51
Q51R1 = "Normal (Q51 Right)",
Q51R2 = "Pain (Q51 Right)",
Q51R3 = "Right laterality (Q51 Right)",
Q51R4 = "Left laterality (Q51 Right)",
Q51R5 = "Jaw open (Q51 Right)",
Q51R6 = "Jaw close (Q51 Right)",
Q51R7 = "Jaw open and close (Q51 Right)",
Q51L1 = "Normal (Q51 Left)",
Q51L2 = "Pain (Q51 Left)",
Q51L3 = "Right laterality (Q51 Left)",
Q51L4 = "Left laterality (Q51 Left)",
Q51L5 = "Jaw open (Q51 Left)",
Q51L6 = "Jaw close (Q51 Left)",
Q51L7 = "Jaw open and close (Q51 Left)"
)
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)\\6.3\\06.3 Non ortho_ICON_OCCLUSION_OMES.xlsx")