尽管R中存在具有类似值的其他字符串,我是否可以仅替换一个字符串

尽管R中存在具有类似值的其他字符串,我是否可以仅替换一个字符串,r,string,replace,na,grepl,R,String,Replace,Na,Grepl,我正在学习R。我想将数据帧列中的“0”字符串替换为NA值。此列包含其他值为“0”的字符串 我用过: For(n in 1:nrow(d2)) { If(grepl(“0”, d2[n,10]) == TRUE) d2[n,10] <- NA For(1中的n:nrow(d2)){ If(grepl(“0”,d2[n,10])==TRUE) d2[n,10]对grep/grepl进行了向量化。因此,我们可以直接在列上创建一个逻辑向量,并将其更改为NA d2[,10][grepl("

我正在学习R。我想将数据帧列中的“0”字符串替换为NA值。此列包含其他值为“0”的字符串

我用过:

For(n in 1:nrow(d2)) {
  If(grepl(“0”, d2[n,10]) == TRUE)
  d2[n,10] <- NA
For(1中的n:nrow(d2)){
If(grepl(“0”,d2[n,10])==TRUE)

d2[n,10]对
grep/grepl
进行了向量化。因此,我们可以直接在列上创建一个逻辑向量,并将其更改为
NA

d2[,10][grepl("^0$", d2[,10])] <- NA

d2[,10][grepl(^0$”,d2[,10])]对
grep/grepl
进行矢量化。因此,我们可以直接在列上创建一个逻辑向量,并将其更改为
NA

d2[,10][grepl("^0$", d2[,10])] <- NA

d2[,10][grepl(“^0$”,d2[,10])]Akrum非常感谢你救了MeeeEakrum非常感谢你救了Meeee