Set-Operations on data.frames

Have you been loooking for a nice way to determine differences of sets of dataframes in R?

There is a very cool package, part of the tidyverse from Hadley Wickham. See here, how simple it is to perform this task in R, with dplyr installed:

library(dplyr)
a <- mtcars[1:10,]
b <- mtcars[6:10,]
# preserve rownames
a$carname <- rownames(a)
b$carname <- rownames(b)
# perform diff-operation 
dplyr::setdiff(a,b)

If you would like to preserve the information contained in the rownames, store the rownames within a seperate column before applying the set-operation:

library(dplyr)
a <- mtcars[1:10,]
b <- mtcars[6:10,]
# preserve rownames
a$carname <- rownames(a)
b$carname <- rownames(b)
# perform diff-operation 
# preserve rownames
a$carname <- rownames(a)
b$carname <- rownames(b)
dplyr::setdiff(a,b)

The dplyr-package is very powerful and allows tons of data-subsetting, aggregating and summarizing-operations. I’ll present further applications in the future.