dat <- data.frame(outcome = rnorm(25),
sex = sample(c("F", "M"), 25, replace = TRUE),
age_group = sample(c(1, 2, 3), 25, replace = TRUE))
> head(dat)
outcome sex age_group
1 1.1423 F 2
2 0.0998 M 1
3 -1.6305 F 2
4 -1.6759 F 1
5 0.3825 F 2
6 0.7274 F 3
I have a dataset that has a continuous outcome
variable. I would like to obtain a LaTeX table of descriptive statistics for this variable stratified by sex
and age_group
. I would like it to look something like this (it doesn't have to have mean (SD) but I want the layout of outcome stratified by age_group and sex):
I've tried the Hmisc
package:
library(Hmisc)
output <- summaryM(outcome ~ sex + age_group, data = dat, test = TRUE)
latex(output, file = "")
but the output looks very different from what I want: