These scoped variants of distinct() extract distinct rows by a selection of variables. Like distinct(), you can modify the variables before ordering with funs().

distinct_all(.tbl, .funs = list(), ...)

distinct_at(.tbl, .vars, .funs = list(), ...)

distinct_if(.tbl, .predicate, .funs = list(), ...)

Arguments

.tbl

A tbl object.

.funs

List of function calls generated by funs(), or a character vector of function names, or simply a function.

Bare formulas are passed to rlang::as_function() to create purrr-style lambda functions. Note that these lambda prevent hybrid evaluation from happening and it is thus more efficient to supply functions like mean() directly rather than in a lambda-formula.

...

Additional arguments for the function calls in .funs. These are evaluated only once, with tidy dots support.

.vars

A list of columns generated by vars(), a character vector of column names, a numeric vector of column positions, or NULL.

.predicate

A predicate function to be applied to the columns or a logical vector. The variables for which .predicate is or returns TRUE are selected. This argument is passed to rlang::as_function() and thus supports quosure-style lambda functions and strings representing function names.

Examples

df <- data_frame(x = rep(2:5, each = 2) / 2, y = rep(2:3, each = 4) / 2) df
#> # A tibble: 8 x 2 #> x y #> <dbl> <dbl> #> 1 1 1 #> 2 1 1 #> 3 1.5 1 #> 4 1.5 1 #> 5 2 1.5 #> 6 2 1.5 #> 7 2.5 1.5 #> 8 2.5 1.5
distinct_all(df)
#> # A tibble: 4 x 2 #> x y #> <dbl> <dbl> #> 1 1 1 #> 2 1.5 1 #> 3 2 1.5 #> 4 2.5 1.5
distinct_at(df, vars(x,y))
#> # A tibble: 4 x 2 #> x y #> <dbl> <dbl> #> 1 1 1 #> 2 1.5 1 #> 3 2 1.5 #> 4 2.5 1.5
distinct_if(df, is.numeric)
#> # A tibble: 4 x 2 #> x y #> <dbl> <dbl> #> 1 1 1 #> 2 1.5 1 #> 3 2 1.5 #> 4 2.5 1.5
# You can supply a function that will be applied before extracting the distinct values # The variables of the sorted tibble keep their original values. distinct_all(df, round)
#> # A tibble: 3 x 2 #> x y #> <dbl> <dbl> #> 1 1 1 #> 2 2 1 #> 3 2 2
arrange_all(df, funs(round(.)))
#> # A tibble: 8 x 2 #> x y #> <dbl> <dbl> #> 1 1 1 #> 2 1 1 #> 3 1.5 1 #> 4 1.5 1 #> 5 2 1.5 #> 6 2 1.5 #> 7 2.5 1.5 #> 8 2.5 1.5