[R] Creating the mean using algebra matrix

Timothy Bates timothy.c.bates at gmail.com
Wed Oct 12 09:05:19 CEST 2011


On Oct 12, 2011, at 12:04 AM, Rolf Turner wrote:
> On 12/10/11 08:31, Timothy Bates wrote:
>> To do matrix multiplication: m x n, the Rows and columns of  m must be equal to the columns and rows of n, respectively.
> No.  The number of columns of m must equal the number of rows of n,
> that's all.  The number of *rows* of m and the number of *columns* of n
> can be anything you like.
> 


Yes, I don't know how I wrote that.. conflating criteria for conformability with the shape of the output,,, 

The easiest way to remember this is to visualize the dimensions of the two matrices side by side:

R1 C1 %*% R2 C2

The adjacent numbers must match (C1 & R2)

The resultant matrix will have dimensions of the outside numbers (R1 C2). 

i.e., 
A = matrix(1:4,nrow=1); B = matrix(1:4,ncol=1); A; B; A %*% B; B %*% A
A
     [,1] [,2] [,3] [,4]
[1,]    1    2    3    4
B
     [,1]
[1,]    1
[2,]    2
[3,]    3
[4,]    4
A %*% B
     [,1]
[1,]   30
B %*% A
     [,1] [,2] [,3] [,4]
[1,]    1    2    3    4
[2,]    2    4    6    8
[3,]    3    6    9   12
[4,]    4    8   12   16



More information about the R-help mailing list