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

From: beatleb <rhelpforum_at_gmail.com>
Date: Tue, 15 Mar 2011 08:12:16 -0700 (PDT)


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.

______________________________________________
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 Tue 15 Mar 2011 - 15:58:53 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 Tue 15 Mar 2011 - 16:10:22 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