0
votes

I am trying to multiply the transpose of a matrix by the original matrix.

B<-matrix(rep(c(10, -10,10), 15), ncol=3, byrow=TRUE)

I then transposed the matrix using t(B) function, giving me a 15 x 3 and 3 x 15 matrix, which I should be able to multiply as B*t(B) or t(B)*B. However, I get an error of 'Error in t(B) * B : non-conformable arrays'

Is this something I'm missing for this? I should be able to multiple either B*t(B) or t(B)*B since you would have a 3x3 matrix or 15 x 15 matrix for the answer.

1
B %*% t(B) is the matrix multiplication. tcrossprod(B) is fasterjogo

1 Answers

1
votes

For matrix multiplication, you should use %*% (* is for element-wise multiplication).

If you want a simple expression, you can try crossprod or tcrossprod, e.g.,

crossprod(B) # equivalent to t(B) %*% B

or

tcrossprod(B) # equivalent to B %*% t(B)