I am trying to create a simple 'for loop' to produce a series of descriptive tables (saved as dataframes) using R but am struggling to do so.
For example, I can create a simple descriptive table (called 'Var_1_tab') like so:
library(janitor)
Var_1<- c("a", "b", "b", "a", "b", "b", "b")
Var_2<- c("b", "b", "a", "a", "a", "b", "a")
Var_3<- c("c", "b", "a", "c", "c", "b", "a")
df<- data.frame(Var_1, Var_2, Var_3)
Var_1_tab<- df %>% janitor::tabyl(Var_1)
I want to use a loop to sequence along each column in my dataframe and produce the same simple descriptive table for each column, storing the result in my global environment as a dataframe. Added bonus would be to be able to name each dataframe as 'Var_1_tab', 'Var_2_tab' etc, for ease of reference.
Can anyone help?
Thanks!!!