Message-ID: <200509082115.j88LF01V027395@tahi.mcs.vuw.ac.nz>
Date: 2005-09-08T21:15:00Z
From: Ray Brownrigg
Subject: generating a vector from clusters of logicals
> From: Troels Ring <tring at gvdnet.dk>
>
> 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 ?
>
How about:
> TF <- c(TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,TRUE,FALSE)
> rep(1:length(rlel <- rle(TF)$lengths), rlel)
[1] 1 1 1 2 2 2 3 3 4
HTH,
Ray Brownrigg