【发布时间】:2020-02-09 20:37:50
【问题描述】:
根据the documentation of the dplyr package:
# The _if() variants apply a predicate function (a function that
# returns TRUE or FALSE) to determine the relevant subset of
# columns.
# mutate_if() is particularly useful for transforming variables from
# one type to another
iris %>% mutate_if(is.factor, as.character)
那么我该如何使用逆形式呢?我想将所有非数字值转换为字符,所以我想这样做:
iris %>% mutate_if(!is.numeric, as.character)
#> Error in !is.numeric : invalid argument type
但这不起作用。或者只选择所有非数字变量:
iris %>% select_if(!is.numeric)
#> Error in !is.numeric : invalid argument type
也不行。
如何将negation 与dplyr 函数一起使用,例如mutate_if()、select_if() 和arrange_if()?
编辑:这可能会在即将发布的 dplyr 1.0.0 中解决:NEWS.md。
【问题讨论】:
标签: r dplyr data-transform