collapse::allNA identifies data.frame as list
Steviey opened this issue · 3 comments
Steviey commented
R latest, collapse latest, Ubuntu 20.04.5 LTS
df <- data.frame(A = c(1, 2, NA, 4), B = c(NA, NA, NA, NA))
result <- collapse::allNA(df)
Gives me:
Error in collapse::allNA(df) : Unsupported type 'list' passed to allNA()
Actually I want to get a result like:
df <-df %>% dplyr::select_if(~!all(is.na(.)))
What can we do here?
Steviey commented
R latest, collapse latest, Ubuntu 20.04.5 LTS
Update:
Got it with:
test<-collapse::get_vars(df,!collapse::allNA)
But is the list error right?
And is there a substitute for:
df <-df %>% dplyr::mutate(across(where(is.factor),as.numeric))
?
SebKrantz commented
allNA()
does not have a data frame method. You can use all(dapply(df, allNA))
. collapse::get_vars(df,!collapse::allNA)
should not work because you are not passing a function to it. Use collapse::get_vars(df, function(x) !collapse::allNA(x))
.
Steviey commented
Okay thx, I missinterpreted 'allv(x, value)', assuming uppercase X.
Then second then seems to be:
settransform(df,get_vars(df, function(x) is.factor(x)) %>% as.numeric())