cumfun | R Documentation |
Calculates the cumulative value of almost any function in the same manner as cumsum
cumfun(frist, FUN = sum, ...)
frist |
A vector of numerical or string values |
FUN |
The function to use. Can be either the function name (as is usually done) or a single character string naming the function. Default is |
... |
Additional arguments, if any, required for the chosen FUN function. See Details. |
If additional arguments are of length one, they are applied to each value in frist
. If they are longer but not equal in length to length(frist)
they will either be truncated or recycled to match.
The builtin functions cumsum
and cumprod
generally are much faster than applying sum
or prod
to this function.
A list of the cumulative calculations generated.
Carl Witthoft, carl@witthoft.com
cumsum
, cumall
, rowCumsums
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')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.