[R] using ddply but preserving some of the outside data
byrnes at msi.ucsb.edu
Thu Aug 6 00:49:53 CEST 2009
OK, I see how this would work for a rolling mean with continuous
observations. However, my actual problem is a bit more complex. I have a
number of observations, not necessarily evenly spaced. So, the data I'm
working with looks somewhat more like what this would produce
sites<-c("a", "b", "c")
And, rather than getting a rolling daily average, let's say I want an
average from any sample points from the previous 20 days.
#now, I want to get the average of the
sub.df<-subset(df, df$dates-date<20 &
Would the rollmean approach still work here?
Gabor Grothendieck wrote:
> In particular, try this:
>> a.wide <- reshape(a.df, dir = "wide", timevar = "dates", idvar = "sites")
>> rollmean(as.zoo(t(a.wide[,-1])), 2)
> 1 56.855685 58.62981 95.14842
> 2 58.049821 58.81659 78.70020
> 3 11.199634 89.91179 76.22853
> 4 1.152741 43.63333 93.03040
View this message in context: http://www.nabble.com/using-ddply-but-preserving-some-of-the-outside-data-tp24834295p24837587.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help