[R] loop question

From: Thomas <thomas.triebs_at_cantab.net>
Date: Thu, 14 Apr 2011 12:28:54 +0100

Dear all,

I am trying to implement the following in a loop:

g <- cbind(c(1, 2, 3), c(1, 2, 3))
h <- cbind(c(1, 2, 3), c(1, 2, 3))
c <- cbind(g[,1]*h[,1], g[,2]*h[,2])


My attempt looks like this but does not produce the desired results as above.

for (i in 1:2) {g<- rowSums(cbind(g[,i]*h[,i]))}

How do I do this correctly?

Many thanks,


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 14 Apr 2011 - 11:35: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 Thu 14 Apr 2011 - 11:40:30 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