如何使用dplyr :: select_if选择非数字列 [英] How to select non-numeric columns using dplyr::select_if
本文介绍了如何使用dplyr :: select_if选择非数字列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要选择所有非数字列。我可以使用 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)
如果我想选择 non怎么办-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
非常感谢您的帮助!
推荐答案
您可以使用 purrr
的 negate()
,如果您使用 library(tidyverse)
而不只是 library(dplyr)
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))
这篇关于如何使用dplyr :: select_if选择非数字列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文