Re: [R] help with coef

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat 21 Oct 2006 - 04:38:06 GMT

Using the builtin BOD data frame:

as.vector(coef(lm(demand ~ Time, BOD)))[2]

On 10/21/06, tom soyer <tom.soyer@gmail.com> wrote:
> Hi,
>
> I am trying to get R to return just the slope of a linear regression line,
> but it seems that R has to return both the slope and the name of the slope.
> For example,
>
> > a=coef(lm(y~miles))
> > a
> (Intercept) miles
> 360.3778 -7.2875
> > names(a)
> [1] "(Intercept)" "miles"
> > a[1]
> (Intercept)
> 360.3778
> > a[2]
> miles
> -7.2875
>
> I don't understand the data structure that's returned from coef(). names(a)
> seems to suggest that coef() returns two columns of data, column one is the
> Intercept, and column two miles. But R keeps telling me that the return
> value from coef() has only one dimension, i.e., a[,2] doesn't work, but a[2]
> works. However, a[2] contains more than the slope, it also has the name of
> the slope. Does anyone know how to access just the slope without its name?
>
> Thanks,
>
> Tom
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



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 Sat Oct 21 14:43:18 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 Sat 21 Oct 2006 - 05:30:11 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.