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

Select only numeric columns from dataframes in a list : RSTUDIO

I have this list of dataframes as follows :

library(carData)

library(datasets)

l = list(Salaries,iris)

I only want to select the numeric columns in this list of datasets. Already tried lapply with the function select_if(is.numeric) but it did not work with me.

Would appreciate the help. Thanks.

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 :

We can use select with where in the newer version of dplyr – loop over the list with map and select the columns of the data.frames

library(purrr)
library(dplyr)
map(l, ~ .x %>%
    select(where(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