Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading