[R] loop question

Thomas thomas.triebs at cantab.net
Thu Apr 14 13:28:54 CEST 2011

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 

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

How do I do this correctly?

Many thanks,


More information about the R-help mailing list