Subset based on list of strings using grepl()?

后端 未结 1 1696
情深已故
情深已故 2021-01-02 01:10

I\'m looking to do something seemingly very simple. I would like to subset a data frame in R using the grepl() command -- or something like it -- on several different phras

相关标签:
1条回答
  • 2021-01-02 01:45

    You can combine your mynames vector with the regular expression operator | and use grep.

    tmp[grep(paste(mynames, collapse='|'), tmp$Name, ignore.case=TRUE),]
    
    #           Name Age Height
    # 1    Mary Anne  31      1
    # 2   Mary Smith  23      2
    # 3 Potter, Mary  23      3
    # 4    mary jane  55      4
    # 5          Bob  32      5
    # 6    bob smith  36      6
    # 7   smith, BOB  45      7
    
    0 讨论(0)
提交回复
热议问题