r - Calculate cumulative standard deviation -


i'm trying calculate standard deviation of values in time series, i'd incrementally advancing 1 day initial date value each time. know there way in r (probably using ddply?) doesn't involve nasty for-loop. 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 way i'm doing now.

result <- c() for(i in 2:nrow(test.df)){ result[i-1] <- sd(test.df[1:i,]$value)} 

use ttr::runsd cumulative=true.

library(ttr) x <- xts(test.df[,2],test.df[,1]) runsd(x, n=1, cumulative=true) 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -