【发布时间】:2016-04-15 12:54:06
【问题描述】:
我有一个包含两列的数据框:
Surname Email
1 house greghouse@gmail.com
2 wilson johnwatson@gmail.com
我想创建一个逻辑向量来检查Surname 是否包含在Email 中。因此结果应该是:
Surname Email CheckEmail
1 house greghouse@gmail.com TRUE
2 wilson johnwatson@gmail.com FALSE
我尝试了grep,但似乎grep 只能在 1 个或多个实例中查找一种模式。 我特别需要在多个实例中寻找多种模式。
> grep(df1$Surname,df1$Email)
[1] 1
Warning message:
In grep(df1$Surname, df1$Email) :
argument 'pattern' has length > 1 and only the first element will be used
【问题讨论】:
标签: r string dataframe contains