Skip to content
Prev 205327 / 398506 Next

Extract vector elements until cumsum <= x

Try this which uses 10 as the check value:

f <- function(acc, x) if (acc + x > 10) x else acc + x
x <- c(4, 6, 2, 7, 4, 1, 4, 8)
Reduce(f, x)
On Sun, Jan 3, 2010 at 10:02 PM, Dgnn <sharkbrainpdx at gmail.com> wrote: