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)
Using the builtin BOD data frame:
as.vector(coef(lm(demand ~ Time, BOD)))[2]
On 10/21/06, tom soyer [EMAIL PROTECTED] 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
Gabor,
Thanks for the code example, but it seems that BOD is not needed. I still
don't understand what is going on with the data structure returned by
coef(). The strangness is illustrated by the following example:
a=coef(lm(y~miles))
is.vector(a)
[1] TRUE
a[2]
miles
-7.2875
a=as.vector(a)
On 10/21/06, tom soyer [EMAIL PROTECTED] wrote:
Gabor,
Thanks for the code example, but it seems that BOD is not needed. I still
demand and Time are columns of BOD so if you omit it then it won't know
where they are.
don't understand what is going on with the data structure returned by
without setting its names attribute:
as.vector(a)
-Christos
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of tom soyer
Sent: Saturday, October 21, 2006 1:00 AM
To: Gabor Grothendieck
Cc: r-help
Subject: Re: [R] help with coef
Gabor,
Thanks for the code
Also try this to look inside the objects:
cc - coef(lm(demand ~ Time, BOD))
dput(cc)
structure(c(8.52142857142858, 1.72142857142857), .Names = c((Intercept),
Time))
cc2 - as.vector(cc)
dput(cc2)
c(8.52142857142858, 1.72142857142857)
from which we see that the only difference in their
PROTECTED] On Behalf Of tom soyer
Sent: Saturday, October 21, 2006 1:00 AM
To: Gabor Grothendieck
Cc: r-help
Subject: Re: [R] help with coef
Gabor,
Thanks for the code example, but it seems that BOD is not needed. I still
don't understand what is going on with the data structure returned