distinct {dplyr} | R Documentation |
Retain only unique/distinct rows from an input tbl. This is an
efficient version of unique
. distinct()
is best-suited
for interactive use, distinct_()
for calling from a function.
distinct(.data, ...) distinct_(.data, ..., .dots)
.data |
a tbl |
... |
Variables to use when determining uniqueness. If there are multiple rows for a given combination of inputs, only the first row will be preserved. |
.dots |
Used to work around non-standard evaluation. See
|
df <- data.frame( x = sample(10, 100, rep = TRUE), y = sample(10, 100, rep = TRUE) ) nrow(df) nrow(distinct(df)) distinct(df, x) distinct(df, y) # You can also use distinct on computed variables distinct(df, diff = abs(x - y))