grep using a character vector with multiple patterns

前端 未结 10 2449
猫巷女王i
猫巷女王i 2020-11-22 04:29

I am trying to use grep to test whether a vector of strings are present in an another vector or not, and to output the values that are present (the matching pat

10条回答
  •  一整个雨季
    2020-11-22 05:14

    This should work:

    grep(pattern = 'A1|A9|A6', x = myfile$Letter)
    

    Or even more simply:

    library(data.table)
    myfile$Letter %like% 'A1|A9|A6'
    

提交回复
热议问题