| 1 |
## From: Christoph Buser <[email protected]> |
| 2 |
## To: maechler@.... |
| 3 |
## Subject: Duplicated |
| 4 |
## Date: Tue, 25 Sep 2007 14:29:46 +0200 |
| 5 |
|
| 6 |
### Changes and more arguments: entirely by MM |
| 7 |
Duplicated <- function(v, incomparables = FALSE, fromLast = FALSE, |
| 8 |
nomatch = NA_integer_) |
| 9 |
{ |
| 10 |
## Purpose: A counting-generalization of duplicated() |
| 11 |
## ---------------------------------------------------------------------- |
| 12 |
## Arguments: a numeric vector |
| 13 |
## ---------------------------------------------------------------------- |
| 14 |
## Author: Martin Maechler & Christoph Buser, Date: Sep 2007 |
| 15 |
|
| 16 |
uv <- unique(nv <- na.omit(v)) |
| 17 |
## easier (but less general?): uv <- unique(nv <- v[!is.na(v)]) |
| 18 |
fv <- factor(nv, levels = uv) |
| 19 |
dup <- duplicated(as.integer(fv), |
| 20 |
incomparables = incomparables, fromLast = fromLast) |
| 21 |
match(v, nv[dup], incomparables = incomparables, nomatch = nomatch) |
| 22 |
} |