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])
g<-rowSums(c)

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,

Thomas

______________________________________________
R-help@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.

Reply via email to