Difference of two character vectors with substring

前端 未结 3 680
死守一世寂寞
死守一世寂寞 2020-12-11 09:09

I have two lists:

a <- c(\"da\", \"ba\", \"cs\", \"dd\", \"ek\")
b <- c(\"zyc\", \"ulk\", \"mae\", \"csh\", \"ddi\", \"dada\")

I want

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 09:32

    We can paste the 'a' elements to a single string with | as the delimiter, use that as pattern in grepl, negate (!) to subset 'b'.

     b[!grepl(paste(a, collapse="|"), b)]
    

提交回复
热议问题