Re: [R] Saving run time in loop

From: Rolf Turner <>
Date: Wed, 20 Apr 2011 19:16:53 +1200

On 20/04/11 18:30, vincent.deluard 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.

It's not at all clear what you are actually trying to do, and the sample code that you give does not work. I.e. it throws an error.

Be more careful and think more clearly.


         Rolf Turner mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed 20 Apr 2011 - 07:20:15 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 - 07:40:32 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive