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\\13 Non Ortho - TEMPOROMANDIBULAR DISORDER PAIN SCREENING QUESTIONNAIRE\\Edit 13. Non Ortho_TEMPOROMANDIBULAR DISORDER PAIN SCREENING QUESTIONNAIRE.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 CÁC BIẾN THEO TỪNG NHÓM THANG ĐO VÀ GHI ĐÈ LÊN df
df <- df %>%
mutate(
# --- 1. Nhóm Giới tính (Gender) ---
Gender = factor(Gender, levels = c(0, 1), labels = c("Male", "Female")),
# --- 2. Nhóm biến A3 (Thang đo 3 mức độ) ---
A3 = factor(A3, levels = c(0, 1, 2),
labels = c("No pain", "Pain comes and goes", "Constant pain")),
# --- 3. Nhóm Yes/No khổng lồ (0: No, 1: Yes) ---
# Bao gồm tất cả các câu hỏi chính và câu hỏi phụ (A41 đến A143)
across(
c(A1,
A41, A42, A43, A44,
A5,
A71, A72, A73, A74,
A8, A81, A82, A83,
A9, A91, A92, A93,
A10, A101, A102, A103,
A11, A111, A112, A113,
A12, A121, A122, A123,
A13, A131, A132, A133,
A14, A141, A142, A143),
~ factor(., levels = c(0, 1), labels = c("No", "Yes"))
)
# Lưu ý: Các biến A2, A6, A15, A16, A17, A18 là câu hỏi mở/điền số,
# nên ta không dùng hàm factor() mã hóa để tránh làm mất dữ liệu chữ/số gốc của bệnh nhân.
)
# 2. GẮN NHÃN MÔ TẢ (LABELS) CHUẨN XÁC THEO TỪNG CÂU HỎI
df <- df %>%
set_variable_labels(
Gender = "Gender",
A1 = "Have you ever had pain in your jaw, in the ear, or in front of the ear on either side?",
A2 = "How many years or months ago did your pain in the jaw temple, in the ear, or in front of the ear first begin?",
A3 = "In the last 30 days, which of the following best describes any pain in your jaw, temples, in the ear, or in front of the ear on either side?",
A41 = "A4.1: Chewing hard or tough food",
A42 = "A4.2: Opening your mouth or moving your jaw forward or side",
A43 = "A4.3: Jaw habits such as holding teeth together, clenching/grinding teeth, or chewing gum",
A44 = "A4.4: Other jaw activities such as talking, kissing, or yawning",
A5 = "In the last 30 days, have you had headaches that included the temple areas of your head?",
A6 = "How many years or months ago did your temple headache first begin",
A71 = "A7.1: Chewing hard or tough food",
A72 = "A7.2: Opening your mouth or moving your jaw forward or side",
A73 = "A7.3: Jaw habits such as holding teeth together, clenching/grinding teeth, or chewing gum",
A74 = "A7.4: Other jaw activities such as talking, kissing, or yawning",
A8 = "In the last 30 days, have you had any jaw joint noises when you moved or used your jaw?",
A81 = "A8.1: R (Right)",
A82 = "A8.2: L (Left)",
A83 = "A8.3: DNK (don't know)",
A9 = "Have you ever had your jaw lock or catch, even for a moment, so that it would not open all the way?",
A91 = "A9.1: R (Right)",
A92 = "A9.2: L (Left)",
A93 = "A9.3: DNK (don't know)",
A10 = "Is the feeling of your jaw getting stuck or locked severe enough to prevent you from opening your mouth and affect your ability to chew or eat?",
A101 = "A10.1: R (Right)",
A102 = "A10.2: L (Left)",
A103 = "A10.3: DNK (don't know)",
A11 = "Was your jaw lock or catch severe enough to limit your jaw opening and interfere with your ability to eat?",
A111 = "A11.1: R (Right)",
A112 = "A11.2: L (Left)",
A113 = "A11.3: DNK (don't know)",
A12 = "Is your jaw currently locked or limited so that your jaw will not open all the way?",
A121 = "A12.1: R (Right)",
A122 = "A12.2: L (Left)",
A123 = "A12.3: DNK (don't know)",
A13 = "In the last 30 days, when you open your mouth wide, did your jaw lock or catch ever for a moment such that you could not close it from this wide open position?",
A131 = "A13.1: R (Right)",
A132 = "A13.2: L (Left)",
A133 = "A13.3: DNK (don't know)",
A14 = "In the last 30 days, when you opened your mouth wide, did your jaw lock or catch even for a moment such that you could not close it from this wide open position?",
A141 = "A14.1: R (Right)",
A142 = "A14.2: L (Left)",
A143 = "A14.3: DNK (don't know)",
A15 = "What brought you to seek treatment",
A16 = "How long have you been experiencing this condition",
A17 = "Have you received treatment anywhere before",
A18 = "Are you currently being treated for any other medical conditions"
)
# 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)\\13\\13. Non Ortho_TEMPOROMANDIBULAR DISORDER PAIN SCREENING QUESTIONNAIRE.xlsx")