Many thanks Dimitris. On Mon, Jul 26, 2010 at 9:13 AM, Dimitris Rizopoulos < d.rizopou...@erasmusmc.nl> wrote:
> have a look at function rollapply() from package zoo. > > I hope it helps. > > Best, > Dimitris > > > On 7/26/2010 8:28 AM, Raghu wrote: > >> Hi >> >> I have 3500 rows of data (say a single column) in a vector. If I want to >> compare every ith element with the simple average of the previous (i-5) >> elements, then I could write something like this: >> >> for(i in 6:NROW(data)){ >> if(data[i] => mean(data[(i-5):i]) (counter[i]=1)} >> } >> >> Is it possible to replicate the above faster in R? >> >> >> > -- > Dimitris Rizopoulos > Assistant Professor > Department of Biostatistics > Erasmus University Medical Center > > Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands > Tel: +31/(0)10/7043478 > Fax: +31/(0)10/7043014 > -- 'Raghu' [[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.