[R] Adding predicted values as a new variable in a data frame

From: Robi Ragan <robi.ragan_at_gmail.com>
Date: Thu 14 Sep 2006 - 05:33:19 GMT


I am running a regression:

ols.reg1 <- lm(y ~ x1 + x2 + x3 + x4)

on a data.frame

and then generating fitted values:

y.hat <- ols.reg1$fitted.values

Then I would like to add these fitted values to the data.frame as a new variable. The problem is that when the values are predicted the resulting output has too few rows. for some reason certian observations do not get predicted values. So this shrinks the column down and I then cannot combine the output into the original data.frame.

If someone could please help I would apreciate it. Stata automatically adds a new column to the data set when you find the fitted values. So having to fight with R just to do something I used to routimely do has made me think of turning back to the dark side. I hope I have just missed something trival in all the help files I have been looking through.

Thanks,

--

Robi Ragan
Graduate Student
Department of Economics
Department of Political Science
The University of Georgia

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu Sep 14 15:40:15 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 14 Sep 2006 - 07:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.