Many thanks for all the quick replies...



On 14/04/2011 13:37, Hao Wu wrote:
> you can use this instead, apply(g*h,1,sum)
>
> On Thu, Apr 14, 2011 at 7:28 PM, Thomas <thomas.triebs@cantab.net 
> <mailto:thomas.triebs@cantab.net>> wrote:
>
>     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 <mailto: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.
>
>


	[[alternative HTML version deleted]]

