Thanks, I had recently seen reference to caTools but had forgotten about it.
Much appreciated. friedman.st...@gmail.com 517-648-6290 -----Original message----- From: Gabor Grothendieck <ggrothendi...@gmail.com> To: Steve Friedman <skfgla...@gmail.com> Cc: r-help@r-project.org Sent: Mon, Apr 4, 2011 13:17:36 GMT+00:00 Subject: Re: [R] moving mean and moving variance functions On Mon, Apr 4, 2011 at 8:30 AM, Steve Friedman <skfgla...@gmail.com> wrote: > Hello > > > Lets say as an example I have a dataframe with the following attributes: > rownum(1:405), colnum(1:287), year(2000:2009), daily(rownum x colnum x year) > and foragePotential (0:1, by 0.01). Â The data is actually stored in a netcdf > file and I'm trying to provide a conceptual version of the data. > > Ok. I need to calculate a moving mean and a moving variance for each cell on > the following temporal > windows - 7 day, 14 day, and 28 day. So far I have code for the moving > average. > > ma <- function(x , n) { > Â Â Â Â Â filter(x, rep(1/n, n), sides = 1) > Â Â Â } Â # note that when the function is used, n is defined for the > temporal period (7, 14, and 28), and x is the input variable. > > > ma7 <- Â ma(dat, 7) Â # where dat is accessing the foraging potential of the > birds. > ma14 <- ma(dat, 14) > ma28 <- ma(dat, 28) > > This works fine. Â What I don't have is the code for a moving variance. > > filter in the function above is included in the stats package and conducts a > linear filtering on a Time Series. > > Is there comparable code some place in R for a moving variance? > See rollmean and rollapply in the zoo package and runmean and runsd in the caTools package. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.