Calculate cumulative standard deviation

r

Solution

Use `TTR::runSD` with `cumulative=TRUE`.

library(TTR)
x <- xts(test.df[,2],test.df[,1])
runSD(x, n=1, cumulative=TRUE)

Problem

I'm trying to calculate the standard deviation of values in a time series, but I'd like to do it incrementally by advancing one day from the initial date value each time. I know there is a way to do this in R (probably using ddply?) that doesn't involve a nasty for-loop. Thanks for any help! ``` d<-seq(from=as.Date("2013-01-01"), to=as.Date("2013-02-01"), by="day") v <-rnorm(32, 10, 5) test.df<-data.frame(the_date=d, value=v) ``` Here's the way I'm doing it now. ``` result <- c() for(i in 2:nrow(test.df)){ result[i-1] <- sd(test.df[1:i,]$value)} ```

Original source

Related problems