0
fit <- lm(R1 ~ R2)

Yields...

Call:
lm(formula = R1 ~ R2)

Residuals:
      Min        1Q    Median        3Q       Max 
-0.128139 -0.016528  0.000349  0.017806  0.125109 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.003785   0.001884   2.009   0.0453 *  
R.2         0.949923   0.043904  21.636   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

I have run an linear regression with these results. Now I want to collect one value, more precisely: fit["coefficients" -> "(Intercept)"].

I try

fit["coefficients"]

which yields

$coefficients
(Intercept)   R2 
0.003785144 0.949923219

How could I extract this 1 value?

Thank you in advance!

Sander
  • 51
  • 6

1 Answers1

0

Function coef() allow to extract coefficients from a lm object. So to get the intercept value, you simply have to use

coef(fit)[1]
xraynaud
  • 2,028
  • 19
  • 29