[R] Adding elements of matrices of different dimensions

From: michael papenfus <papenfus_at_gmail.com>
Date: Tue 27 Jun 2006 - 15:28:03 EST


If I have two matrices:

> a<-matrix(1:5,ncol=1)

     [,1]
[1,] 1
[2,] 2
[3,] 3
[4,] 4
[5,] 5
> b<-matrix(1:50,ncol=10)

     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 1 6 11 16 21 26 31 36 41 46
[2,] 2 7 12 17 22 27 32 37 42 47
[3,] 3 8 13 18 23 28 33 38 43 48
[4,] 4 9 14 19 24 29 34 39 44 49
[5,] 5 10 15 20 25 30 35 40 45 50

How can I add a[1,1] to each column in the first row of b. and the then add a[2,1] to each column in second row of b and so on.

I know there must be a way to use the apply function or nested for loops but I can't seem to get it working in R.
thanks,
michael

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jun 27 15:31:25 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 27 Jun 2006 - 18:12:29 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.