0

This will be a pretty basic question, but when I type:

reg = lm(y ~ x) 
# then call reg,
reg

reg$coefficients

I get the two regression parameter estimates. But I would like to be able to pick them out without getting "(Intercept)" and "Elapsed_Time" attached to them.

1 Answers1

2

Here's an example on a built in data set

 # set up the lm object
 carsregcoef <- lm(dist~speed,cars)$coefficients

 # remove names
 names(carsregcoef) <- NULL

 # print it:
 carsregcoef
 [1] -17.579095   3.932409

See ?names for details

You could always write a little function to strip the names. Maybe something like:

 unname <- function(x) {
              names(x) <- NULL  
              x
            }

Then you could do this sort of thing:

carsregcoef <- unname(lm(dist~speed,cars)$coefficients)
Glen_b
  • 7,883
  • 2
  • 37
  • 48