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\\14.Non Ortho - THE ORAL BEHAVIOR CHECKLIST\\EDIT 14.Non Ortho_THE ORAL BEHAVIOR CHECKLIST.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 = factor(Gender, levels = c(0, 1), labels = c("Male", "Female")),
# --- 2. Nhóm Tần suất ban đêm (VM1, VM2) ---
# Đã sửa lỗi đánh máy "Night/mouth" thành "Night/month"
across(
c(VM1, VM2),
~ factor(., levels = c(0, 1, 2, 3, 4),
labels = c("None",
"<1 Night/month",
"1-3 Nights/month",
"1-3 Nights/week",
"4-7 Nights/week"))
),
# --- 3. Nhóm Tần suất ban ngày đặc thù (VM3) ---
VM3 = factor(VM3, levels = c(0, 1, 2, 3, 4),
labels = c("None", "Rarely", "Occasionally", "Frequently", "Always")),
# --- 4. Nhóm Tần suất hành vi ban ngày (VM4 đến VM21) ---
across(
c(VM4, VM5, VM6, VM7, VM8, VM9, VM10, VM11, VM12, VM13,
VM14, VM15, VM16, VM17, VM18, VM19, VM20, VM21),
~ factor(., levels = c(0, 1, 2, 3, 4),
labels = c("None of time",
"A little of the time",
"Some of the time",
"Most of the time",
"All of the time"))
)
)
# 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",
VM1 = "Clench or grind teeth when asleep, based on any information you may have", # Sửa lỗi usleep, bases on
VM2 = "Sleeping in a position that puts pressure on the jaw (for example, on stomach, on the side)",
VM3 = "Grind teeth together during waking hours",
VM4 = "Clench teeth together during waking hours",
VM5 = "Press, touch, or hold teeth together other than while eating (that is, contact between upper and lower teeth)",
VM6 = "Hold, tighten, or tense muscles without clenching or bringing teeth together",
VM7 = "Hold or jut jaw forward or to the side",
VM8 = "Press tongue forcibly against teeth",
VM9 = "Place tongue between teeth",
VM10 = "Bite, chew, or play with your tongue, cheeks or lips",
VM11 = "Hold jaw in rigid or tense position, such as to brace or protect the jaw",
VM12 = "Hold between the teeth or bite objects as hair, pipe, pencil, pens, fingernails, etc.",
VM13 = "Use chewing gum",
VM14 = "Play musical instruments that involves use of mouth or jaw (for example, woodwind, brass, string instruments)",
VM15 = "Lean with your hand on the jaw, such as cupping or resting the chin in the hand",
VM16 = "Chew food on one side only",
VM17 = "Eating between meals (that is, food that requires chewing)",
VM18 = "Sustained talking (for example, teaching, sales, customer service)",
VM19 = "Singing",
VM20 = "Yawning",
VM21 = "Holding telephone between your head and shoulders"
)
# 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)\\14\\14.Non Ortho_THE ORAL BEHAVIOR CHECKLIST.xlsx")