用r中的1替换大于零的值 [英] Replace values greater than zero with 1 in r
本文介绍了用r中的1替换大于零的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 tidyverse
获取数据帧 df
,并将所有非零值替换为1.
I want to use tidyverse
to take a dataframe df
and replace all non-zero values to a value of 1.
推荐答案
以下内容会将所有非零数值转换为1:
The following will convert all non-zero numeric values to 1:
df.richness %>% mutate_if(is.numeric, ~1 * (. != 0))
同时
df.richness %>% mutate_if(is.numeric, ~1 * (. > 0))
将对那些大于零的对象执行此操作.
will do that with those greater than zero.
这篇关于用r中的1替换大于零的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文