Guest User

Untitled

a guest
Sep 14th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. Select similar and unique values in a data frame
  2. df = data.frame(email_one=c("one@gkn.com","two@wern.com","three@fu.cin",
  3. "four@huo.com","five@hoi.com"), email_two=c("ten@hoinse.com",
  4. "four@huo.com","two@wern.com","five@hoi.com","six@ihoio.com"))
  5.  
  6. # Elements present in both columns
  7. intersect(df[[1]], df[[2]])
  8. [1] "two@wern.com" "four@huo.com" "five@hoi.com"
  9.  
  10. # Elements of column 1 that are not in column 2
  11. setdiff(df[[1]], df[[2]])
  12. [1] "one@gkn.com" "three@fu.cin"
  13.  
  14. # Elements of column _2_ that are not in column _1_
  15. setdiff(df[[2]], df[[1]])
  16. [1] "ten@hoinse.com" "six@ihoio.com"
Add Comment
Please, Sign In to add comment