Re: [R] Help on vectorizing

2008-03-09 Thread Charles C. Berry
On Sun, 9 Mar 2008, Gabor Grothendieck wrote: > Try this: > > r <- unlist(sapply(x, function(x) c(rep(0, x), 1))) And in large problems ( length(x) >> 1000 ), this will be faster still r <- rep( rep( 0:1, length(x) ), rbind(x,1) ) HTH, Chuck > x2 <- diff(c(0, which(r==1))) - 1 > iden

Re: [R] Help on vectorizing

2008-03-09 Thread Gabor Grothendieck
Try this: r <- unlist(sapply(x, function(x) c(rep(0, x), 1))) x2 <- diff(c(0, which(r==1))) - 1 identical(x, x2) On Sun, Mar 9, 2008 at 7:55 PM, remko duursma <[EMAIL PROTECTED]> wrote: > > Dear R-helpers, > > I have two problems that I don't know how to vectorize (but would like to > because m