In this example I want to apply the count() function to every character variable in a dataset.
library(dplyr)
library(purrr)
nycflights13::flights %>%
select_if(is.character) %>%
map(., count)
But I receive the error message:
Error in UseMethod("groups") : no applicable method for
'groups' applied to an object of class "character"
I'm not sure how to interpret the error message or update my code. Similar code works for numeric variables, but factor variables produce a similar error message to character variables
nycflights13::flights %>%
select_if(is.numeric) %>%
map(., mean, na.rm = TRUE)
nycflights13::flights %>%
select_if(is.character) %>%
mutate_all(as.factor) %>%
map(., count)
count()isn't meant to be used on character vectors -- you get the same error withcount(letters[1:10]). - MrFlickcountis designed to work on a data frame, not a vector. - alistairemap(., table)or%>% count(.)but they perform different things - CPak