Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

funique

Fast Unique Elements / Rows


Description

funique is a substantially faster alternative to unique. It is generic with a default vector method and a data frame method.

Usage

funique(x, ...)

## Default S3 method:
funique(x, sort = FALSE, method = c("auto", "radix", "hash"), ...)

## S3 method for class 'data.frame'
funique(x, cols = NULL, sort = FALSE, ...)

Arguments

x

a atomic vector or data frame / list of equal-length columns.

sort

logical. TRUE orders the unique elements / rows. FALSE returns unique values in order of first occurrence, however numeric values are only provided in order of first occurrence when method = "hash" i.e. the radix method always sorts numeric data.

method

an integer or character string specifying the method of computation:

Int. String Description
1 "auto" automatic selection: hash for character, logical or if length(x) < 500, else radix.
2 "radix" use radix ordering to determine unique values.
3 "hash" use index hashing to determine unique values.
cols

compute unique rows according to a subset of columns. Columns can be selected using column names, indices, a logical vector or a selector function (i.e. is.character). Note: All columns are returned.

...

arguments passed to radixorderv, e.g. decreasing or na.last. Only applicable in funique.default if method = "radix".

Details

If x is a data frame / list and all rows are already unique, then x is returned. Otherwise a copy of x with duplicate rows removed is returned. See qF for some additional computational details.

Value

x with duplicate elements/rows removed.

See Also

Examples

funique(mtcars$cyl)
funique(gv(mtcars, c(2,8,9)))
funique(mtcars, cols = c(2,8,9))

collapse

Advanced and Fast Data Transformation

v1.5.3
GPL (>= 2) | file LICENSE
Authors
Sebastian Krantz [aut, cre], Matt Dowle [ctb], Arun Srinivasan [ctb], Laurent Berge [ctb], Dirk Eddelbuettel [ctb], Josh Pasek [ctb], Kevin Tappe [ctb], R Core Team and contributors worldwide [ctb], Martyn Plummer [cph], 1999-2016 The R Core Team [cph]
Initial release
2021-03-05

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.