Hi, I basically have the same question. I’ve looked through several options but haven't found a way to create a table that shows: means(sd) for multiple variables organized by group.
Using my data (below), I can use 'group_by()' and 'across()' to estimate the 𝑥̄ and sd.
means_sds <- list(
mean = ~mean(.x, na.rm = TRUE),
sd = ~sd(.x, na.rm = TRUE)
)
vars.avg.sd <- dat.sm %>%
group_by(group.factor) %>%
summarise(across(is.numeric, means_sds))
Yet, I have to transpose the data to approximate my goal but, the 𝑥̄ and sd are on alternating rows.
Any help or suggestions would be greatly appreciated.
Cheers,
~ Jason the #rstatsnewbie
t(vars.avg.sd)
Data
dput(head(dat.sm, 30))
structure(list(group.factor = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L), .Label = c("HC", "CLBP",
"FM", "TRUE"), class = "factor"), slpQual = c(0, 1, 1, 1, 1,
0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 2, 0, 2, 1,
1, 2, 1, 2), slpLat = c(1, 0, 2, 1, 1, 0, 1, 1, 1, 2, 0, 1, 1,
1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 2, 0, 1, 1, 1, 3), slpDur = c(1,
0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0,
1, 0, 2, 1, 1, 0, 1, 3), slpEff = c(0, 0, 1, 0, 1, 1, 0, 0, 0,
0, 0, 0, 0, 3, 3, 0, 3, 1, 0, 0, 3, 0, 0, 3, 1, 3, 0, 1, 1, 3
), slpDist = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), slpMeds = c(0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1,
0, 0, 0, 0, 0, 3, 1), slpDayFcn = c(0, 0, 1, 0, 1, 0, 0, 1, 0,
1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
), psqi_Global = c(3, 2, 7, 3, 5, 3, 3, 4, 2, 6, 0, 3, 4, 6,
7, 1, 7, 5, 6, 3, 5, 2, 6, 4, 8, 6, 4, 5, 8, 13), slpQualraw = c(0,
1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0,
2, 0, 2, 1, 1, 2, 1, 2), slpLatraw = c(12, 6, 33, 17, 17, 6,
19.5, 32, 12, 33, 6, 7, 12, 12, 18, 11, 17, 22, 24.5, 6, 13.5,
12, 22, 11, 33, 11, 17, 17, 19.5, 109), slpDurraw = c(6.5, 7.5,
7, 7.5, 8, 7, 7, 7.5, 7.5, 6.5, 9, 7.25, 8, 8, 6.5, 8, 7, 7,
7.5, 7, 7, 7.5, 7, 8, 5, 6, 7, 7.5, 7, 4.5), slpEffraw = c(92.8571428571429,
100, 82.3529411764706, 93.75, 84.2105263157895, 82.3529411764706,
93.3333333333333, 88.2352941176471, 100, 92.8571428571429, 100,
90.625, 100, 25, 20.9677419354839, 94.1176470588235, 21.875,
82.3529411764706, 85.7142857142857, 87.5, 21.875, 93.75, 93.3333333333333,
24.8062015503876, 83.3333333333333, 20, 93.3333333333333, 83.3333333333333,
82.3529411764706, 50), slpDistraw = c(2, 3, 1, 4, 5, 3, 5, 8,
1, 7, 0, 2, 7, 5, 6, 1, 6, 3, 4, 5, 8, 5, 7, 3, 3, 4, 3, 16,
11, 13), slpMedsraw = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 3, 1), slpDayFcnraw = c(0,
0, 1, 2, 1, 0, 0, 1, 0, 1, 0, 0, 1, 2, 3, 0, 3, 0, 1, 3, 2, 0,
2, 0, 0, 0, 0, 3, 3, 0), psqi_Globalraw = c(113.357142857143,
117.5, 125.352941176471, 125.25, 116.210526315789, 98.3529411764706,
124.833333333333, 137.735294117647, 120.5, 141.357142857143,
115, 107.875, 129, 53, 55.4677419354839, 114.117647058824, 55.875,
115.352941176471, 125.714285714286, 109.5, 52.375, 118.25, 134.333333333333,
46.8062015503876, 126.333333333333, 42, 121.333333333333, 128.833333333333,
126.852941176471, 179.5), ess_total = c(5, 5, 4, 7, 10, 2, 5,
5, 4, 9, 6, 10, 8, 9, 6, 8, 9, 3, 6, 10, 8, 10, 3, 0, 10, 6,
6, 6, 9, 6), isi_total = c(NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 3L, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA), bdi_total = c(0, 1, 1, 13, 5, 0, 1, 6, 0,
7, 0, 2, 0, 6, 0, 3, 1, 0, 0, 7, 12, 5, 7, 0, 2, 8, 1, 9, 12,
4), mcgill_total = c(0, 0, 0, 0, 0, 0, 9, 0, 0, 4, 0, 1, 0, 5,
0, 0, 0, 0, 0, 38, 34, 16, 0, 0, 0, 5, 2, 14, 0, 0), TIB = c(7,
7.5, 8.5, 8, 9.5, 8.5, 7.5, 8.5, 7.5, 7, 9, 8, 8, 32, 31, 8.5,
32, 8.5, 8.75, 8, 32, 8, 7.5, 32.25, 6, 30, 7.5, 9, 8.5, 9)), row.names = c(NA,
30L), class = "data.frame")