Skip to content
Back to formatted view

Raw Message

Message-ID: <1303281046240-3462228.post@n4.nabble.com>
Date: 2011-04-20T06:30:46Z
From: vincent.deluard
Subject: Saving run time in loop

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.