[R] lm on matrix data
bqcaomail at gmail.com
Wed Oct 10 16:35:47 CEST 2012
I have a question about using lm on matrix, have to admit it is very
trivial but I just couldn't find the answer after searched the mailing
list and other online tutorial. It would be great if you could help.
I have a matrix "trainx" of 492(rows) by 220(columns) that is my x,
and trainy is 492 by 1. Also, I have the newdata testx which is 240
(rows) by 220 (columns). Here is what I got:
py <- predict(lm(trainy ~ trainx ), data.frame(testx))
'newdata' had 240 rows but variable(s) found have 492 rows
The fitting formula I intended is: trainy ~ trainx[,1] + trainx[,2] +
Any help, please?
More information about the R-help