I am attempting to make a nested table using the tables
package in r that can then be added into a knitr document.
I would like to make a table where each row is a different categorical variable in the data set and each column is the frequency and percent of each response option.
I would like the result to look something like this
Variable 1-5 times 6-10 times 11-15 times
freq Percent freq percent freq percent
eating 5 33 5 33 5 33
drinking 5 33 5 33 5 33
Here is some code that should allow for the production of the above table.
eating <- c("1-5 times", "1-5 times", "1-5 times","1-5 times","1-5 times", "6-10 times","6-10 times","6-10 times","6-10 times","6-10 times", "11-15 times","11-15 times","11-15 times","11-15 times","11-15 times")
drinking<-c("1-5 times", "1-5 times", "1-5 times","1-5 times","1-5 times", "6-10 times","6-10 times","6-10 times","6-10 times","6-10 times", "11-15 times","11-15 times","11-15 times","11-15 times","11-15 times")
eating<-factor(eating)
drinking<-factor(drinking)
df<-data.frame(eating,drinking)
Does anyone know a way of doing this? Either with the tables
package or something else?