
Chapter 9 Creating tables
In our final document we will want tables to describe our data. Below we create a table which contains demographic information on our sample.
# Method 1 using rstatix
<- df.nirs %>%
tbl.demo distinct(Subject, .keep_all = TRUE) %>%
group_by(group, gender) %>%
::get_summary_stats(age, type = "mean_sd") %>%
rstatixselect(-c("variable")) %>%
::rename(
dplyr"Group" = "group",
"Sex" = "gender",
"Mean Age" = "mean",
"SD" = "sd"
)
# Method 2 using RMisc
<- Rmisc::summarySE(data = df,
journey_time measurevar = "journey_time_avg",
groupvars = c("service","year"),
conf.interval = 0.95,
na.rm = TRUE,
.drop = TRUE)
# Taking the mean and confidence interval =============
# __Method #1 - Easy #########
<- Rmisc::summarySE(data = df,
journey_time measurevar = "journey_time_avg",
groupvars = c("service","year"),
conf.interval = 0.95,
na.rm = TRUE,
.drop = TRUE)
# To get a descriptive table
<- Rmisc::summarySE(data = df.mri %>%
tbl.descFullACAP filter(metric == "FA", mriloc == "CC_FMajor"),
measurevar = "age",
groupvars = c("group","gender"),
conf.interval = 0.95,
na.rm = TRUE,
.drop = TRUE) %>%
::clean_names("upper_camel") %>%
janitorrename(
"CI" = "Ci",
"SE" = "Se",
"SD" = "Sd"
%>%
) mutate_at(vars(Age,SD,SE,CI), funs(round(., 3)))
::resave(tbl.descFullACAP, file = "data/tables.RData") #resave a list of tables that I'll use in the .Rmd file.
cgwtools
# __Method 2 - More options
%>%
df group_by(Channel) %>%
summarise_each(funs(mean, sd))
<- data.table(df)
dt group_by(dt, Channel_46)
# __Method 2b - Not so Easy ##################
# descriptives <- demo%>%dplyr::group_by(AthleteType)%>%
# dplyr::summarise(
# "Mean Height (cm)" = round(mean(Height_cm),2)
# , "Mean Weight (kg)" = round(mean(Weight_kg),2)
# , "Mean Age (Years)" = round(mean(AgeInYears),2)
# , "Number of Concussions" = round(mean(NumPriorConc),2)
# , "Number of Diagnosed Concussions" = round(mean(NumDiagConc),2)
# , "Number of Undiagnosed Concussions" = round(mean(NumUndiagConc),2)
# )
You may also choose to write these to an xlsx file
<- iris
df ::write.xlsx2(df, "test.xlsx", row.names = FALSE, sheetName = "SheetNumber1", append = TRUE) # uses the xlsx package xlsx