Skip to main content
2 of 4
dplyr is no longer a new package, so I deleted the word "new"
Andrew Barr
  • 3.8k
  • 4
  • 20
  • 28

You can do joins as well using Hadley Wickham's awesome dplyr package.

Here is how you can do most of the joins in the original question with dplyr

library(dplyr)

#make sure that CustomerId cols are both type numeric
#they ARE not using the provided code in question and dplyr will complain
df1$CustomerId <- as.numeric(df1$CustomerId)
df2$CustomerId <- as.numeric(df2$CustomerId)


#inner
inner_join(df1, df2)

#left outer
left_join(df1, df2)

#right outer (just reverse argument order)
left_join(df2, df1)
Andrew Barr
  • 3.8k
  • 4
  • 20
  • 28