Re: [R] Saving run time in loop

From: Dennis Murphy <djmuser_at_gmail.com>
Date: Wed, 20 Apr 2011 01:20:26 -0700

Hi:

Perhaps rollapply() in the zoo package might be helpful.

Dennis

On Tue, Apr 19, 2011 at 11:30 PM, vincent.deluard <vincent.deluard_at_trimtabs.com> wrote:
> Hi r users,
>
> I am trying to compute the "moving variance" of a large matrix. I now use a
> loop but I am looking for a faster solution. Here is a sample of the code.
>
> Source= matrix(rnorm(400),ncol=100)
> variances= matrix(rep(NA,4*100),ncol=100)
>
> for (i in 1:80) {variances[,i]=apply(Source[,i:(i+80)],1,var)}
>
> any idea? Many thanks in advance.
>
>
> Vincent.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Saving-run-time-in-loop-tp3462228p3462228.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_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.
>



R-help_at_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. Received on Wed 20 Apr 2011 - 08:24:02 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Apr 2011 - 08:30:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive