I need to tabulate many categorical variables. I am using the function freq from questionr library to do it. My data frame is called esp.
I create an object with the categorical variables as following:
symp <- c("asthma", "flu", "cough", "sivilance", "fever")
I used the library foreach to tabulte all variables in symp:
library(foreach)
foreach(esp[symp]) %do% questionr::freq(i, cum = TRUE, total = TRUE, na.last = T)
However, it did not work, the result was the following:
[[1]]
n % val% %cum val%cum
3 1 100 100 100 100
Total 1 100 100 100 100
[[2]]
n % val% %cum val%cum
3 1 100 100 100 100
Total 1 100 100 100 100
[[3]]
n % val% %cum val%cum
3 1 100 100 100 100
Total 1 100 100 100 100
[[4]]
n % val% %cum val%cum
3 1 100 100 100 100
Total 1 100 100 100 100
[[5]]
n % val% %cum val%cum
3 1 100 100 100 100
Total 1 100 100 100 100
I need a table for each variable.
How can I tabulate all the variables without repeating the code?
Thanks