| funique {collapse} | R Documentation |
funique is an efficient alternative to unique (or unique.data.table, kit::funique, dplyr::distinct).
fnunique is an alternative to NROW(unique(x)) (or data.table::uniqueN, kit::uniqLen, dplyr::n_distinct).
The collapse versions are versatile and highly competitive.
funique(x, ...) ## Default S3 method: funique(x, sort = FALSE, method = "auto", ...) ## S3 method for class 'data.frame' funique(x, cols = NULL, sort = FALSE, method = "auto", ...) ## S3 method for class 'sf' funique(x, cols = NULL, sort = FALSE, method = "auto", ...) # Methods for indexed data / compatibility with plm: ## S3 method for class 'pseries' funique(x, sort = FALSE, method = "auto", drop.index.levels = "id", ...) ## S3 method for class 'pdata.frame' funique(x, cols = NULL, sort = FALSE, method = "auto", drop.index.levels = "id", ...) fnunique(x) # Fast NROW(unique(x))
x |
a atomic vector or data frame / list of equal-length columns. | |||||||||||||||||||||
sort |
logical. | |||||||||||||||||||||
method |
an integer or character string specifying the method of computation:
| |||||||||||||||||||||
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 (e.g. | |||||||||||||||||||||
... |
arguments passed to | |||||||||||||||||||||
drop.index.levels |
character. Either |
If all values/rows are already unique, then x is returned. Otherwise a copy of x with duplicate rows removed is returned. See group for some additional computational details.
The sf method simply ignores the geometry column when determining unique values.
Methods for indexed data also subset the index accordingly.
x with duplicate elements/rows removed.
No matrix method is provided. Please see kit::funique for a fast alternative with a matrix method.
fndistinct, group, Fast Grouping and Ordering, Collapse Overview.
funique(mtcars$cyl) funique(gv(mtcars, c(2,8,9))) funique(mtcars, cols = c(2,8,9)) fnunique(gv(mtcars, c(2,8,9)))