我有一个列表,其中每个元素都是可变长度的字符串向量 如,
reqr:
chr[1:3] "sales" "communication" "leadership"
chr[1:2] "IT" "customer service"
chr[1:4] "team player" "CSS" "html" "english"
我有一个向量A = c("IT", "CSS", "english")
我想从列表中删除出现在向量A中的字符串,我该怎么做?
答案 0 :(得分:4)
设置操作很好......
lapply(reqr, setdiff, y=A)
#[[1]]
#[1] "sales" "communication" "leadership"
#
#[[2]]
#[1] "customer service"
#
#[[3]]
#[1] "team player" "html"
答案 1 :(得分:3)
您可以将lapply
与match
lapply(reqr, function(x) x[is.na(match(x, A))])
#$a
#[1] "sales" "communication" "leadership"
#$b
#[1] "customer service"
#$c
#[1] "team player" "html"