[R] Duplicated non contiguous element in a list
Peter McMahan
peter.mcmahan at gmail.com
Fri Mar 16 17:55:51 CET 2007
Maybe not the most efficient, but here's a vector-level solution:
non.contig.dupes <- function(x){
is.dup <- x %in% x[duplicated(x)]
is.con <- c(x[-length(x)]==x[-1],F) | c(F,x[-length(x)]==x[-1])
is.dup & !is.con}
On Mar 16, 2007, at 11:14 AM, Bruno C.. wrote:
> Hello,
>
> Given a vector I would like to rapidly identify duplicated non
> contiguous elements.
> Given for example
> c(1, 1, 2, 3, 2, 4, 5, 6, 4)
> I would like to get:
> FALSE FALSE TRUE FALSE TRUE TRUE FALSE FALSE TRUE
>
> In fact I need to check this on the columns of a matrix!
> I can do that of couse with loops but is there any function already
> available?
>
> Thanks
>
>
> ------------------------------------------------------
> Passa a Infostrada. ADSL e Telefono senza limiti e senza canone
> Telecom
> http://infostrada.it
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list