I would like some help on creating formatted tables in R - whether it's just using the normal IDE or R Markdown. There are two main things that I'd like to do:
- Present the descriptive statistics (Mean, Median, Min, Max) by group based on different columns
- Present the descriptive statistic based on the total sample (ungrouped data)
Sample data:
df <- data.frame(Gender = c("F", "M", "F", "M", "M", "M", "M", "F", "M", "M"),
Young = c("Y", "N", "Y", "N", "Y", "N", "Y", "N", "Y", "N"),
Age = c("14", "25", "13", "24", "14", "25", "13", "24", "10", "26"),
Location = c("Suburb", "Rural", "Suburb", "Rural","Suburb", "Rural","Suburb", "Rural","Suburb", "Rural"))
Expected results
Variable | Mean | Median | Max | Min |
---|---|---|---|---|
Gender | ||||
Female | ||||
Male | ||||
Location | ||||
Suburb | ||||
Rural | ||||
TOTAL |
Is there a way to do this in R?