Wrappers of set operations in data.table. Only difference is it could be applied to non-data.table data frames by recognizing and coercing them to data.table automatically.
intersect_dt(x, y, all = FALSE) union_dt(x, y, all = FALSE) setdiff_dt(x, y, all = FALSE) setequal_dt(x, y, all = TRUE)
x | A data.frame |
---|---|
y | A data.frame |
all | Logical. When |
A data.table
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> <num> <num> <num> <num> <fctr> #> 1: 4.7 3.2 1.3 0.2 setosa #> 2: 4.6 3.1 1.5 0.2 setosaintersect_dt(x, y, all=TRUE) # intersect all#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> <num> <num> <num> <num> <fctr> #> 1: 4.7 3.2 1.3 0.2 setosa #> 2: 4.6 3.1 1.5 0.2 setosasetdiff_dt(x, y) # except#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> <num> <num> <num> <num> <fctr> #> 1: 4.9 3 1.4 0.2 setosasetdiff_dt(x, y, all=TRUE) # except all#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> <num> <num> <num> <num> <fctr> #> 1: 4.9 3.0 1.4 0.2 setosa #> 2: 4.7 3.2 1.3 0.2 setosaunion_dt(x, y) # union#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> <num> <num> <num> <num> <fctr> #> 1: 4.9 3.0 1.4 0.2 setosa #> 2: 4.7 3.2 1.3 0.2 setosa #> 3: 4.6 3.1 1.5 0.2 setosa #> 4: 5.0 3.6 1.4 0.2 setosaunion_dt(x, y, all=TRUE) # union all#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> <num> <num> <num> <num> <fctr> #> 1: 4.9 3.0 1.4 0.2 setosa #> 2: 4.7 3.2 1.3 0.2 setosa #> 3: 4.7 3.2 1.3 0.2 setosa #> 4: 4.6 3.1 1.5 0.2 setosa #> 5: 4.7 3.2 1.3 0.2 setosa #> 6: 4.6 3.1 1.5 0.2 setosa #> 7: 5.0 3.6 1.4 0.2 setosasetequal_dt(x, x2, all=FALSE) # setequal#> [1] TRUEsetequal_dt(x, x2) # setequal all#> [1] FALSE