[R] question re: "summarry.lm" and NA values

r user ruser2006 at yahoo.com
Tue Aug 15 16:01:13 CEST 2006


Is there a way to get the following code to include
NA values where the coefficients are “NA”?

((summary(reg))$coefficients)

explanation:

Using a loop, I am running regressions on several
“subsets” of “data1”.

“reg <- ( lm(lm(data1[,1] ~., data1[,2:l])) )”

My regression has 10 independent variables, and I
therefore expect 11 coefficients.
After each regression, I wish to save the coefficients
and standard errors of the coefficients in a table
with 22 columns.

I successfully extract the coefficients using the
following code:
“reg$coefficients”

I attempt to extract the standard errors using :

aperm((summary(reg))$coefficients)[2,]

((summary(reg))$coefficients)

My problem:
For some of my subsets, I am missing data for one or
more of the independent variables.  This of course
causes the coefficients and standard erros for this
variable to be “NA”.

Is there a way to include the NA standard errors, so
that I have the same number of standard erros and
coefficients for each regression, and can then store
the coefficients and standard erros in my table of 22
columns?



More information about the R-help mailing list