[R] lm on matrix data
Baoqiang Cao
bqcaomail at gmail.com
Wed Oct 10 16:35:47 CEST 2012
Hi,
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))
Warning message:
'newdata' had 240 rows but variable(s) found have 492 rows
The fitting formula I intended is: trainy ~ trainx[,1] + trainx[,2] +
.. +trainx[,220].
Any help, please?
Best,
Baoqiang
More information about the R-help
mailing list