[R] Help with "apply"

From: M.Ribeiro <mresendeufv_at_yahoo.com.br>
Date: Thu, 12 May 2011 14:23:08 -0700 (PDT)


Hello R gurus,

I have a simple routine using for loops that i was just trying to make it faster

y <- rnorm(10)
Nindiv <- 10
x <-matrix(sample(c(0:2),50,re = T),10)
gtemp <- rnorm(10)
ycorr <- array(0,c(Nindiv,1))
for (i in 1:Nindiv) {

	for (k in 1:ncol(x)) {
		ycorr[i] <- y[i] - x[i,k]*gtemp[k]
	}

}

It works fine but I wanted to make it faster and I think an apply function could probably solve this problem.
Any suggestions? Thanks

--
View this message in context: http://r.789695.n4.nabble.com/Help-with-apply-tp3518773p3518773.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 Thu 12 May 2011 - 22:21:47 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 Fri 13 May 2011 - 04:50:07 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