Skip to content
Back to formatted view

Raw Message

Message-ID: <s3205864.090@lp-msg1.co.ihc.com>
Date: 2005-09-08T21:27:26Z
From: Greg Snow
Subject: generating a vector from clusters of logicals

Try:

x <- c(TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,TRUE)
tmp <- rle(x)
tmp$values <- seq(along=tmp$lengths)
new.x <- inverse.rle(tmp)
new.x
 


Greg Snow, Ph.D.
Statistical Data Center, LDS Hospital
Intermountain Health Care
greg.snow at ihc.com
(801) 408-8111

>>> Troels Ring <tring at gvdnet.dk> 09/08/05 03:03PM >>>
dear friends,
I have a vector of clusters of TRUE and FALSE like 
c(TRUE,TRUE,TRUE...,FALSE,FALSE,FALSE,....TRUE,TRUE...) and want to
make 
that into a vector
of c(1,1,1,1...2,2,2,2,.....3,3,3,3) increasing the number assigned to
each 
cluster as they change.
How would I do that ?

Best wishes

Troels Ring, Aalborg, Denmark

______________________________________________
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