How to the operator NOT with is.numeric

I want to select all variables that are not numeric using select_if of tidyverse.

I tried:

mydata.dataframe %>%
  select_if(!is.numeric)

But I have an error message.
What is the correct way to do it please.

>Solution :

is.numeric is a function. !, by contrast, negates a logical value. Applying ! to a function makes no sense. You need to call the function and negate its result.

In general you’d do the following:

select_if(function (x) ! is.numeric(x))

Or, using the lambda notation of tidyeval:

select_if(~ ! is.numeric(.x))

But R has a function factory to negate the result of a function:

select_if(Negate(is.numeric))

Leave a Reply