Duplicated {sfsmisc} | R Documentation |
Counting-Generalization of duplicated()
Description
Duplicated() generalizes the duplicated
method for
vectors, by returning indices of “equivalence classes” for
duplicated entries and returning nomatch
(NA
by default)
for unique entries.
Note that duplicated()
is not TRUE
for the first time a
duplicate appears, whereas Duplicated()
only marks unique
entries with nomatch
(NA
).
Usage
Duplicated(v, incomparables = FALSE, fromLast = FALSE, nomatch = NA_integer_)
Arguments
v |
a vector, often character, factor, or numeric. |
incomparables |
a vector of values that cannot be compared,
passed to both |
fromLast |
logical indicating if duplication should be considered
from the reverse side, i.e., the last (or rightmost) of identical
elements would correspond to |
nomatch |
passed to |
Value
an integer vector of the same length as v
. Can be used as a
factor
, e.g., in split
,
tapply
, etc.
Author(s)
Christoph Buser and Martin Maechler, Seminar fuer Statistik, ETH Zurich, Sep.2007
See Also
uniqueL
(also in this sfsmisc package);
duplicated
, match
.
Examples
x <- c(9:12, 1:4, 3:6, 0:7)
data.frame(x, dup = duplicated(x),
dupL= duplicated(x, fromLast=TRUE),
Dup = Duplicated(x),
DupL= Duplicated(x, fromLast=TRUE))