在dplyr中过滤和取消过滤 [英] filter and unfilter in dplyr

查看:71
本文介绍了在dplyr中过滤和取消过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在base R中执行以下操作的dplyr类似物是什么?

What would be the dplyr analog of performing the following operation in base R?

iris$Sepal.Length[iris$Sepal.Length>2] <- iris$Sepal.Length[iris$Sepal.Length>2] * 10

我正在尝试使用过滤器,但无法返回到原始数据集(没有 join

I am trying to use filter but cannot go back to the original data set (without a join)

推荐答案

您可以将 mutate ifelse 结合使用,以获得与以下相同的结果@alistaire的评论:

You can use mutate with ifelse to get the same results as comments from @alistaire:

iris %>% mutate(Sepal.Length = ifelse(Sepal.Length > 2, Sepal.Length * 10, Sepal.Length))

这篇关于在dplyr中过滤和取消过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆