尝试将列与列表进行匹配,如果使用ifelse
进行匹配,则返回“ match”
我已经尝试过了:
> df$b <- ifelse(grepl(df1,df$value), 'match', NA)
Warning message:
In grepl(df1, df$value) :
argument 'pattern' has length > 1 and only the first element will be used
value b
<int> <chr>
1 1 NA
2 2 NA
3 3 NA
4 4 NA
5 5 match
6 6 NA
7 7 NA
8 8 NA
9 9 NA
10 10 NA
我想要得到的是:
value b
<int> <chr>
1 1 NA
2 2 NA
3 3 NA
4 4 NA
5 5 match
6 6 match
7 7 match
8 8 match
9 9 match
10 10 match
提前谢谢!
答案 0 :(得分:2)
您需要%in%
运算符:
df$b <- ifelse(df$value %in% df1,'match',NA)