[R] Fill vector more efficient than element by element?

beatleb rhelpforum at gmail.com
Tue Mar 15 16:12:16 CET 2011


Dear R useRs,

I am a newbie. Currently, my script is quick long, therefor I am trying to
improve the efficiency of my script. 
I use often a version of the following code, the script below is just a
simple example, but I especially try to improve the last three lines:

matrix1<-diag(100)
a=2

try<-rep(0,10)
for (i in 1:10){
try[i]<-(matrix1[a*(i+5),7]+matrix1[a*(i+7),8]-matrix1[a*(i+8),9])/matrix1[a*(i+6),a*(i+6)]}

Is it possible to obtain the same result, but more efficient? 

Thank you! 

--
View this message in context: http://r.789695.n4.nabble.com/Fill-vector-more-efficient-than-element-by-element-tp3356871p3356871.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list