On Wed, Aug 16, 2006 at 10:42:35AM +0300, Atte Tenkanen wrote: > 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
How about rle? rle(VECTOR)$values should do the same thing. Don't know about efficiency, though. -- Jarimatti Valkonen ______________________________________________ R-help@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.