Skip to content
Prev 99808 / 398498 Next

Adding predicted values as a new variable in a data frame

?na.exclude should help you: my guess is that you asked (by using the 
default) na.action = na.omit) for rows with missing values to be excluded 
from the residuals. But since you have not mentioned missing values, we 
have to guess what 'for some reason' was: please note the footer of this 
messag.
On Thu, 14 Sep 2006, Robi Ragan wrote:

            
Hmm, no data frame is mentioned: you want a data= argument.
Please use the accessor functions and not dive into the internal details, 
e.g.

y.hat <- fitted(ols.reg1)

BTW: where did you get the use of ols.reg1$fitted.values from?
fit <- lm(formula, data=data_frame, na.action=na.exclude)
data_frame$fitted <- fitted(fit)
The above looks trivial to me.  It was not in R or S when lm was first 
introduced (1991 White Book), but was added last century (thanks to the 
ideas and persistent advocacy of Terry Therneau).