Reputation: 131
I have a list of words
[[1]]
[1] Hello
[2] all
[3] the
[4] world
[[2]]
[1] world
[2] my
[3] Hi
And a data frame which contains for each word its frequency in the text:
Var1 Freq
Hello 54
all 178
the 53
entire 57
world 49
I would like to know if is there any way to remove each string of the data frame from the list of strings. For example as a result I will have, if I delete the word "Hello" I will get:
[[1]]
[1] all
[2] the
[3] world
[[2]]
[1] world
[2] my
[3] Hi
PS: Another example of @Julius
(l <- list(letters[1:2], letters[2:3]))
# [[1]]
# [1] "a" "b"
# [[2]]
# [1] "b" "c"
(r <- letters[2])
# [1] "b"
The result will be like this :
[1] "c"
because all the letters before "b" with "b" are deleted.
Upvotes: 2
Views: 344
Reputation: 48201
(l <- list(letters[1:2], letters[2:3]))
# [[1]]
# [1] "a" "b"
#
# [[2]]
# [1] "b" "c"
(r <- letters[2])
# [1] "b"
lapply(l, setdiff, r)
# [[1]]
# [1] "a"
#
# [[2]]
# [1] "c"
Upvotes: 2