Analogous function for distinct
in dplyr
distinct(.data, ..., .keep_all = FALSE)
data.table
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.
If TRUE
, keep all variables in data.table. If a combination of ... is not distinct,
this keeps the first row of values.
data.table
a = as.data.table(iris)
b = as.data.table(mtcars)
a %>% distinct(Species)
#> Species
#> <fctr>
#> 1: setosa
#> 2: versicolor
#> 3: virginica
b %>% distinct(cyl,vs,.keep_all = TRUE)
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num>
#> 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