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

unipos

Extract Positions of Unique Elements


Description

unipos returns the positions of those elements returned by unique.

Usage

unipos(x, incomparables = FALSE, order = c("original","values","any"), ...)
## S3 method for class 'integer64'
unipos(x, incomparables = FALSE, order = c("original","values","any")
, nunique = NULL, method = NULL, ...)

Arguments

x

a vector or a data frame or an array or NULL.

incomparables

ignored

order

The order in which positions of unique values will be returned, see details

nunique

NULL or the number of unique values (including NA). Providing nunique can speed-up when x has no cache. Note that a wrong nunique can cause undefined behaviour up to a crash.

method

NULL for automatic method selection or a suitable low-level method, see details

...

ignored

Details

This function automatically chooses from several low-level functions considering the size of x and the availability of a cache. Suitable methods are hashmapupo (simultaneously creating and using a hashmap) , hashupo (first creating a hashmap then using it) , sortorderupo (fast ordering) and orderupo (memory saving ordering).
The default order="original" collects unique values in the order of the first appearance in x like in unique, this costs extra processing. order="values" collects unique values in sorted order like in table, this costs extra processing with the hash methods but comes for free. order="any" collects unique values in undefined order, possibly faster. For hash methods this will be a quasi random order, for sort methods this will be sorted order.

Value

an integer vector of positions

Author(s)

Jens Oehlschlägel <Jens.Oehlschlaegel@truecluster.com>

See Also

unique.integer64 for unique values and match.integer64 for general matching.

Examples

x <- as.integer64(sample(c(rep(NA, 9), 1:9), 32, TRUE))
unipos(x)
unipos(x, order="values")

stopifnot(identical(unipos(x),  (1:length(x))[!duplicated(x)]))
stopifnot(identical(unipos(x),  match.integer64(unique(x), x)))
stopifnot(identical(unipos(x, order="values"),  match.integer64(unique(x, order="values"), x)))
stopifnot(identical(unique(x),  x[unipos(x)]))
stopifnot(identical(unique(x, order="values"),  x[unipos(x, order="values")]))

bit64

A S3 Class for Vectors of 64bit Integers

v4.0.5
GPL-2 | GPL-3
Authors
Jens Oehlschlägel [aut, cre], Leonardo Silvestri [ctb]
Initial release
2020-08-29

We don't support your browser anymore

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