Reputation: 33
I have (long) list. How to remove element if I don't know its index? Alternativly how to find element's index (then I can use list[-index]). Example; I have list:
[[1]]
[1] "A" "B" "C" "D"
[[2]]
[1] "C" "D" "B" "C"
[[3]]
[1] "B" "C" "D" "A"
and i want to remove
to.remove
[1] "A" "B" "C" "D"
Upvotes: 0
Views: 174
Reputation: 1830
If you're looking for exact matches, you can use identical, in combination with sapply to look at each element in the list:
myList <- myList[!sapply(myList, identical, c("A", "B", "C", "D")]
Upvotes: 2