Re: [R] using ddply but preserving some of the outside data

2009-08-06 Thread xavier . chardon
quot;R help" Envoyé: Mercredi 5 Août 2009 21h00:40 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne Objet: [R] using ddply but preserving some of the outside data I have a bit of a quandy. I'm working with a data set for which I have sampled sites at a variety of dates. I wa

Re: [R] using ddply but preserving some of the outside data

2009-08-05 Thread Gabor Grothendieck
Its not the evenly spaced that makes it work -- its that you want the same number of observations to contribute to each mean even if they are not equally spaced. In your case since you want different numbers of observations to contribute to each mean you will need a different approach: library(zo

Re: [R] using ddply but preserving some of the outside data

2009-08-05 Thread jebyrnes
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 set.seed(2003) sites<-

Re: [R] using ddply but preserving some of the outside data

2009-08-05 Thread Gabor Grothendieck
In particular, try this: > library(zoo) > 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.6 93.03040 On Wed, Aug 5, 2009 a

Re: [R] using ddply but preserving some of the outside data

2009-08-05 Thread jebyrnes
Interesting. While this will work for a single site, however, for multiple sites or other grouping variables, I'm left with the same problem of efficiently going from one data from to the other. David Winsemius wrote: > > > > library(zoo) > ?rollmean > > David Winsemius, MD > Heritage Labo

Re: [R] using ddply but preserving some of the outside data

2009-08-05 Thread David Winsemius
library(zoo) ?rollmean On Aug 5, 2009, at 3:00 PM, Jarrett Byrnes wrote: I have a bit of a quandy. I'm working with a data set for which I have sampled sites at a variety of dates. I want to use this data, and get a running average of the sampled values for the current and previous dat

[R] using ddply but preserving some of the outside data

2009-08-05 Thread Jarrett Byrnes
I have a bit of a quandy. I'm working with a data set for which I have sampled sites at a variety of dates. I want to use this data, and get a running average of the sampled values for the current and previous date. I originally thought something like ddply would be ideal for this, howe