Im trying to run dplyr::count() on an arbitrary set of variables in one data set. If I manually run count() once for each variable, I get the expected results. But when I try to put count() in a for loop to automatically run each variable in a set of variables, I got an error. It seems like the problem is how I pass the variable to count() in a for loop. I know that count() accepts its variables without quotes and for some reason R cannot say that what I pass is a variable.
Ive tried to fix this, including passing variables like data$var1 , quo(var1) , enquo(var1) , var1 , "var1" , quo(data$var1) and enquo(data$var1) , as well as an unquoting iterator with !! . I also tried to specify the arguments of count() as count(x=data, var=i) , but this called count() to return the total number of rows in the data as a counter for each iteration. If you have any ideas on what causes the error or how I can fix it, I am very grateful for listening to them!
The following is a minimal reproducible example based on the lubridate set included in lubridate .
# This code requires some of the packages in tidyverse. library(dplyr) library(lubridate)
source share