Skip to content
Prev 139034 / 398513 Next

Help on vectorizing

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 <remkoduursma at hotmail.com> wrote: