R data frame string contains: Does column 1 contain column 2?

回眸只為那壹抹淺笑 提交于 2019-12-02 05:52:26

Try with library("stringi") and:

df1$CheckEmail <- stri_detect_fixed(df1$Email, df1$Surname)

Here's a base R approach using mapply with grepl:

transform(df, CheckEmail = mapply(grepl, Surname, Email))
#  Surname                Email CheckEmail
#1   house  greghouse@gmail.com       TRUE
#2  wilson johnwatson@gmail.com      FALSE

Here's a base R option using Vectorize with grepl:

df1$CheckEmail <- Vectorize(grepl)(df1$Surname, df1$Email)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!