[R] predict.lm "variables found" question

Larry White
Thu, 09 Nov 2006 19:33:04 -0000

hello,

I'm trying to predict some values based on a linear regression model.
I've created the model using one dataframe, and have the prediction
values in a second data frame (call it newdata). There are 56 rows in
the dataframe used to create the model and 15 in newdata.

I ran predict(model1, newdata) and get the warning: 'newdata' had 15
rows but variable(s) found have 56 rows

When i checked help(predict.lm) I found this:

"Variables are first looked for in newdata and then searched for in
the usual way (which will include the environment of the formula used
in the fit). A warning will be given if the variables found are not of
the same length as those in newdata if it was supplied. "

My questions are - how can I just get predicted values for the 15 rows
in the newdata data frame, and if that's not possible, how can I tell
which of the 56 predicted values are derived from newdata only, if
any.

Thanks in advance for your help.

Larry