mtcars$model <- rownames(mtcars)
first <- mtcars[1:20, ]
second <- mtcars[10:32, ]
intersect(first, second)
union(first, second)
setdiff(first, second)
setdiff(second, first)
union_all(first, second)
setequal(mtcars, mtcars[32:1, ])
# Handling of duplicates:
a <- data.frame(column = c(1:10, 10))
b <- data.frame(column = c(1:5, 5))
# intersection is 1 to 5, duplicates removed (5)
intersect(a, b)
# union is 1 to 10, duplicates removed (5 and 10)
union(a, b)
# set difference, duplicates removed (10)
setdiff(a, b)
# union all does not remove duplicates
union_all(a, b)
Run the code above in your browser using DataLab