Description Usage Arguments Details Value Author(s) See Also Examples
unique
returns a vector like x
but with duplicate elements/rows removed.
1 2 3 |
x |
a vector or a data frame or an array or |
incomparables |
ignored |
order |
The order in which unique values will be returned, see details |
nunique |
NULL or the number of unique values (including NA). Providing |
method |
NULL for automatic method selection or a suitable low-level method, see details |
... |
ignored |
This function automatically chooses from several low-level functions considering the size of x
and the availability of a cache.
Suitable methods are hashmapuni
(simultaneously creating and using a hashmap)
, hashuni
(first creating a hashmap then using it)
, sortuni
(fast sorting for sorted order only)
, sortorderuni
(fast ordering for original order only)
and orderuni
(memory saving ordering).
The default order="original"
returns unique values in the order of the first appearance in x
like in unique
, this costs extra processing.
order="values"
returns unique values in sorted order like in table
, this costs extra processing with the hash methods but comes for free.
order="any"
returns 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.
For a vector, an object of the same type of x
, but with only
one copy of each duplicated element. No attributes are copied (so
the result has no names).
Jens Oehlschlägel <Jens.Oehlschlaegel@truecluster.com>
unique
for the generic, unipos
which gives the indices of the unique
elements and table.integer64
which gives frequencies of the unique elements.
1 2 3 4 5 6 7 8 | x <- as.integer64(sample(c(rep(NA, 9), 1:9), 32, TRUE))
unique(x)
unique(x, order="values")
stopifnot(identical(unique(x), x[!duplicated(x)]))
stopifnot(identical(unique(x), as.integer64(unique(as.integer(x)))))
stopifnot(identical(unique(x, order="values")
, as.integer64(sort(unique(as.integer(x)), na.last=FALSE))))
|
Loading required package: bit
Attaching package bit
package:bit (c) 2008-2012 Jens Oehlschlaegel (GPL-2)
creators: bit bitwhich
coercion: as.logical as.integer as.bit as.bitwhich which
operator: ! & | xor != ==
querying: print length any all min max range sum summary
bit access: length<- [ [<- [[ [[<-
for more help type ?bit
Attaching package: 'bit'
The following object is masked from 'package:base':
xor
Attaching package bit64
package:bit64 (c) 2011-2012 Jens Oehlschlaegel
creators: integer64 seq :
coercion: as.integer64 as.vector as.logical as.integer as.double as.character as.bin
logical operator: ! & | xor != == < <= >= >
arithmetic operator: + - * / %/% %% ^
math: sign abs sqrt log log2 log10
math: floor ceiling trunc round
querying: is.integer64 is.vector [is.atomic} [length] format print str
values: is.na is.nan is.finite is.infinite
aggregation: any all min max range sum prod
cumulation: diff cummin cummax cumsum cumprod
access: length<- [ [<- [[ [[<-
combine: c rep cbind rbind as.data.frame
WARNING don't use as subscripts
WARNING semantics differ from integer
for more help type ?bit64
Attaching package: 'bit64'
The following object is masked from 'package:bit':
still.identical
The following objects are masked from 'package:base':
%in%, :, is.double, match, order, rank
integer64
[1] <NA> 3 4 6 8 1 9 2 7 5
integer64
[1] <NA> 1 2 3 4 5 6 7 8 9
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.