no applicable method for 'filter_' applied to an object of class "c('double', 'numeric')"

Viewed 22204

Using the below code, I am trying to filter my dataset so that only those who are CG_less14==0 & CG_High14==0 to be selected. I got an error: no applicable method for 'filter_' applied to an object of class "c('double', 'numeric')". Is something wrong with my code?

married_noncare <- filter (all_sample, CG_less14==0 & CG_High14==0)

1 Answers

It is possible that the columns are factor.. One option is to convert to numeric or characteer

library(dplyr)
filter(all_sample, as.character(CG_Less14) == 0 & as.character(CG_High14) == 0)

Or with filter_at

all_sample %>%
      filter_at(vars(CG_Less14, CG_High14), all_vars(as.character(.) == 0))
Related