Why can't I use negative indexing with select_at() ?

I want to filter my training data against a list of variables, and remove variables with a certain amount of NA values. I can select those variables if I pass them to vars(names(. . .)), but I can't use a negative to remove the same variables.

Why doesn't this work? What is the tidy way to do this?

I often use the select helper one_of() (or -one_of()) in a situation like this.

Some pseudo-code:

train %>%
     select_at(vars(-one_of(names(...))))

where you replace ... with your dataset/condition for choosing the names.

4 Likes