I'm trying to run a looped chi-square dataframe
. I'm using map
and possibly
, both from purrr
, to allow the loop to run even if an error is thrown. Somewhere in my data.frame, I have a column that apparently has less than two values -- I can't find it. But, that's why I'm trying to run possibly
. But, I'm now getting an error that says: Can't convert a list to function. I'm not sure how to reconcile this error. I've gotten a replicable example that throws the error using the mtcars
data.frame.
library(tidyverse)
df <- mtcars %>%
mutate(z = 0)
map(df, function(x){
possibly(chisq.test(df$gear, x), otherwise = NA)
})
# Error: Can't convert a list to function
# In addition: Warning message:
# In chisq.test(df$gear, x) :
# Show Traceback
#
# Rerun with Debug
# Error: Can't convert a list to function
Any advice?