Subtract sets so that rest of the similar multiple elements are retained in the result

Viewed 421

For example, I have 2 chairs and one table in set1 and 1 chair in set2. I want to subtract set2 from set1 and want the result as c("chair", "table")

set1 <- c("chair", "chair", "table")
set2 <- c("chair")

setdiff(set1, set2)

gives "table"

3 Answers
Related