Analogous function for distinct in dplyr

distinct_dt(data, ..., keep_all = FALSE)

Arguments

data

data.frame

...

Optional variables to use when determining uniqueness. If there are multiple rows for a given combination of inputs, only the first row will be preserved. If omitted, will use all variables.

keep_all

If TRUE, keep all variables in data.frame. If a combination of ... is not distinct, this keeps the first row of values.

Value

data.table

See also

Examples

iris %>% distinct_dt(Species)
#> Species #> 1: setosa #> 2: versicolor #> 3: virginica
iris %>% distinct_dt(Species,keep_all = TRUE)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1: 5.1 3.5 1.4 0.2 setosa #> 2: 7.0 3.2 4.7 1.4 versicolor #> 3: 6.3 3.3 6.0 2.5 virginica
mtcars %>% distinct_dt(cyl,vs)
#> cyl vs #> 1: 6 0 #> 2: 4 1 #> 3: 6 1 #> 4: 8 0 #> 5: 4 0
mtcars %>% distinct_dt(cyl,vs,keep_all = TRUE)
#> mpg cyl disp hp drat wt qsec vs am gear carb #> 1: 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 #> 2: 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 #> 3: 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 #> 4: 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 #> 5: 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2