It appears that while grep
has an invert argument, grepl
does not.
看起来,虽然grep有一个反转参数,但是grepl没有。
I would like to subset for using 2 filters
我想对使用两个过滤器进行子集划分
data$ID[grepl("xyx", data$ID) & data$age>60]
How can I subset for age>60 and ID not containing "xyx"? What I did is
我怎样才能将>60和不含“xyx”的ID子集?我所做的是
data$ID[abs(grepl("xyx", data.frame$ID)-1) & data$age>60]
which apparently works, but looks awful and unintuitive. Is there a nicer solution/argument?
这显然是可行的,但看起来很糟糕而且不直观。有更好的解决方案/参数吗?
Thanks
谢谢
1 个解决方案
#1
42
grepl
returns a logical vector. You can use the !
operator if you want the opposite result.
grepl返回一个逻辑向量。您可以使用!运营商如果你想相反的结果。
data$ID[!grepl("xyx", data$ID) & data$age>60]
#1
42
grepl
returns a logical vector. You can use the !
operator if you want the opposite result.
grepl返回一个逻辑向量。您可以使用!运营商如果你想相反的结果。
data$ID[!grepl("xyx", data$ID) & data$age>60]