我有一个包含两列的数据框:
Surname Email
1 house [email protected]
2 wilson [email protected]
我想创建一个逻辑向量来检查是否Surname
包含在Email
。因此结果应该是:
Surname Email CheckEmail
1 house greghouse@gmail.com TRUE
2 wilson [email protected] FALSE
I tried 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
尝试用library("stringi")
and:
df1$CheckEmail <- stri_detect_fixed(df1$Email, df1$Surname)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)