distinct {dplyr} | R Documentation

## Select distinct/unique rows.

### Description

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.

### Usage

    distinct(.data, ...)

    distinct_(.data, ..., .dots)

### Arguments

`.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 `vignette("nse")` for details.

### Examples

    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))

[Package dplyr version 0.4.3 Index]