Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Select similar and unique values in a data frame
- df = data.frame(email_one=c("one@gkn.com","two@wern.com","three@fu.cin",
- "four@huo.com","five@hoi.com"), email_two=c("ten@hoinse.com",
- "four@huo.com","two@wern.com","five@hoi.com","six@ihoio.com"))
- # Elements present in both columns
- intersect(df[[1]], df[[2]])
- [1] "two@wern.com" "four@huo.com" "five@hoi.com"
- # Elements of column 1 that are not in column 2
- setdiff(df[[1]], df[[2]])
- [1] "one@gkn.com" "three@fu.cin"
- # Elements of column _2_ that are not in column _1_
- setdiff(df[[2]], df[[1]])
- [1] "ten@hoinse.com" "six@ihoio.com"
Add Comment
Please, Sign In to add comment