[R] generating a vector from clusters of logicals

2005-09-08 Thread Troels Ring
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 Tro

Re: [R] generating a vector from clusters of logicals

2005-09-08 Thread Achim Zeileis
On Thu, 08 Sep 2005 23:03:03 +0200 Troels Ring wrote: > 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 > eac

Re: [R] generating a vector from clusters of logicals

2005-09-08 Thread Ray Brownrigg
> From: Troels Ring <[EMAIL PROTECTED]> > > 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.

Re: [R] generating a vector from clusters of logicals

2005-09-08 Thread Greg Snow
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 [EMAIL PROTECTED] (801) 408-8111 >>> Troels Ring <[EMAIL PROTECTED]> 09/0