OGeek|极客世界-中国程序员成长平台

标题: r - How to select non-numeric columns using dplyr::select_if [打印本页]

作者: 菜鸟教程小白    时间: 2022-9-1 00:11
标题: r - How to select non-numeric columns using dplyr::select_if

I need to select all columns that are not numeric. I can select all numeric columns easily using select_if:

mtcars %>% select_if(is.numeric)

What if I want to select non-numeric columns? I tried:

mtcars %>% select_if(!is.numeric)

But I got error message below:

Error in !is.numeric : invalid argument type

Thanks a lot for help!



Best Answer-推荐答案


You can use purrr's negate() which is included if you use library(tidyverse) rather than just library(dplyr)

library(tidyverse)
iris %>% select_if(negate(is.numeric))
[dbther]




欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4