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

前端 未结 3 1177
难免孤独
难免孤独 2021-01-24 19:35

I have a dataframe with two columns:

  Surname                Email
1   house  greghouse@gmail.com
2  wilson johnwatson@gmail.com

I want to cre

相关标签:
3条回答
  • 2021-01-24 20:08

    Try with library("stringi") and:

    df1$CheckEmail <- stri_detect_fixed(df1$Email, df1$Surname)
    
    0 讨论(0)
  • 2021-01-24 20:24

    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
    
    0 讨论(0)
  • 2021-01-24 20:24

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

    df1$CheckEmail <- Vectorize(grepl)(df1$Surname, df1$Email)
    
    0 讨论(0)
提交回复
热议问题