[R] How to remove similar successive objects from a vector?
Atte Tenkanen
attenka at utu.fi
Wed Aug 16 09:42:35 CEST 2006
Is there some (much) more efficient way to do this?
VECTOR=c(3,2,4,5,5,3,3,5,1,6,6);
NEWVECTOR=VECTOR[1];
for(i in 1:(length(VECTOR)-1))
{
if((identical(VECTOR[i], VECTOR[i+1]))==FALSE){
NEWVECTOR=c(NEWVECTOR,VECTOR[i+1])}
}
> VECTOR
[1] 3 2 4 5 5 3 3 5 1 6 6
> NEWVECTOR
[1] 3 2 4 5 3 5 1 6
_______________________________
Atte Tenkanen
University of Turku, Finland
More information about the R-help
mailing list