foo <- 'abcdefcghicklmno'
grepfoo <-function(x,y) grep(y,x)
cumfoo <- cumfun(unlist(strsplit(foo,'')), FUN=grepfoo, y = 'c')
bar <- rnorm(1000,1)
cumsd <- cumfun(bar,FUN=sd)
plot(unlist(cumsd),type='l')
# compare with input std dev
lines(c(0,1000),c(1,1),lty=2,col='red')
Run the code above in your browser using DataLab