[R] Multrix-vector multiplication

Steven Yen syen04 at gmail.com
Sat Aug 22 15:43:54 CEST 2015


I had trouble with matrix multiplication when a matrix reduces to a
vector.  In the following, lines 1 and 2 work when matrices u and a are
both of order 2.
Lines 3 and 5 do not work (message is matrix not conformable) when u is (T
x 1) and a is (1 x 2) and This causes a problem for users of other matrix
languages such as Gauss and MATLAB.
Inserting line 4 makes it work, which is annoying. But, is it proper/safe
to make it work by inserting line 4? Other approaches?
Thank you!

1 a<-solve(s22)%*%s21 # (2 x 2) <- (2 x 2) %*% (2 x 2)
2 uc<-u%*%v$a         # (T x 2) <- (T x 2) %*% (2 x 2)

3 a<-solve(s22)%*%s21 # (1 x 2) <- (1 x 1) %*% (1 x 2)
4 a<-as.matrix(a)     # This line makes it work. OK? Other approaches?
5 uc<-u%*%v$a         # (T x 1) %*% (1 x 2)

	[[alternative HTML version deleted]]



More information about the R-help mailing list