# Set the working directory to the location of the stroke paper files setwd("C:/Users/Administrator/Desktop/Stroke_Paper") data <- read.csv("mytable.csv") #-----------------------Data Format Transformation------------------------- str(data) # Convert columns 5 to 23 to factor type, excluding the outcome variable data[,c(5:23)] <- lapply(data[,c(5:23)], as.factor) str(data) summary(data) # Note: The outcome variable should not be converted to factor type # Display categorical data table(data$zaifa) # Categorical data #-------------------------1. Baseline Information Table--------------------------- # Continuous variables are reported as [Normal] mean ± standard deviation (SD) or [Non-normal] median interquartile range (IQR) # Categorical variables are represented as count (percentage) ## ----Normality Test---- # Shapiro-Wilk test (sample size < 5000, P < 0.05 indicates non-normality) lapply(data[,c(24:76)], shapiro.test) ## ----Create Baseline Information Table---- library(tableone) tab1 <- CreateTableOne( vars = colnames(data[,c(5:76)]), # All variables to be described factorVars = colnames(data[,c(5:23)]), # Categorical variables strata = "zaifa", # Stratification variable data = data, addOverall = TRUE ) tab1 # Print the table, handling non-normal variables and formatting tab <- print(tab1, nonnormal = colnames(data[,c(24:76)]), # Variables with non-normal distribution noSpaces = TRUE, # Remove spaces added for alignment showAllLevels = TRUE) # Show all levels of categorical variables # Write the table to a CSV file in English write.csv(tab, "C:/Users/Administrator/Desktop/Stroke_Paper/Baseline_Information_Table.csv")