美文网首页
[dplyr]-Set operations

[dplyr]-Set operations

作者: 43daf5f8181f | 来源:发表于2016-08-03 17:21 被阅读10次
> a <- c("a","b","c")
> b <- c("b","c","d","b","d")

> setdiff(testa, testb)
[1] "a"

> setdiff(testb, testa)
[1] "d"

> union(testa, testb)
[1] "a" "b" "c" "d"

> intersect(testb, testa)
[1] "b" "c"

适用于 data frame

mtcars$model <- rownames(mtcars)
first <- mtcars[1:20, ]
second <- mtcars[10:32, ]

intersect(first, second)
union(first, second)
setdiff(first, second)
setdiff(second, first)

相关文章

网友评论

      本文标题:[dplyr]-Set operations

      本文链接:https://www.haomeiwen.com/subject/hjoqsttx.html