Reputation: 269
I have a list, where each element is vector of strings, of variable length e.g.,
reqr:
chr[1:3] "sales" "communication" "leadership"
chr[1:2] "IT" "customer service"
chr[1:4] "team player" "CSS" "html" "english"
I have a vector, A = c("IT", "CSS", "english")
I want to remove strings from the list which appear in vector A, how do I go about this?
Upvotes: 2
Views: 147
Reputation: 389295
You can use lapply
along with 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"
Upvotes: 3
Reputation: 93938
Set operations are good...
lapply(reqr, setdiff, y=A)
#[[1]]
#[1] "sales" "communication" "leadership"
#
#[[2]]
#[1] "customer service"
#
#[[3]]
#[1] "team player" "html"
Upvotes: 4