[R] remove multiple elements from vector

Bastian Offermann bastian2507hk at yahoo.co.uk
Sat Sep 27 15:30:23 CEST 2008


Hello all,

one brief question

I would like to remove double/triple elements from a vector, e.g.

0 1 1 1 1 2 2 2 4 5 6 6

but keep one of these multiple ones. Should look like this finally:

0 1 2 4 5 6

My function does not work somehow

for(i in 2 : length(x)) {
                                 if(x[i]==x[i-1]) x <- x[-(i-1)]
                             }

any suggestion? Thanks.



More information about the R-help mailing list