根据列值 r 更改行中的值 [英] Change values in row based on a column value r

查看:27
本文介绍了根据列值 r 更改行中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 R 新手,有一个相当简单的问题,我就是想不出答案.在我的例子中,我将使用一个有 3 列的数据框,但我的实际数据集是 139 列和 10000 行.

I am new to R with a fairly simple question, I just can't figure out the answer. For my example I will use a data frame with 3 columns, but my actual data set is 139 columns with 10000 rows.

如果 C 列中同一行中的值包含一个值

,我想用 NA 替换给定行中的所有值.10.

I want to replace all of the values in a given row with NA if the value in the same row in column C contains a value < 10.

假设我的所有列都是数字或整数值.

Assume that all of my columns are either number or integer values.

所以我想取数据框:

x=data.frame(c(5,9,2),c(3,4,6),c(12,9,11))
names(x)=c("A","B","C")

并用 NA 替换第 2 行以创建

and replace row 2 with NA to create

y=data.frame(c(5,"NA",2),c(3,"NA",6),c(12,"NA",11))
names(y)=c("A","B","C")

谢谢!

推荐答案

怎么样:

x[x$C <10 ,] <- NA

这篇关于根据列值 r 更改行中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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