Hi, I've done a linear fit on my data and I would like to get back the a (time) coefficient ... mod<-lm(res_sql2$Lx0x~0+time) result<-data.frame() result<-coef(mod) print("result") print(result) [1] "result" time 0.02530191 But I would like just the value 0.02530191 ... I tried result$time but it doesn't work ... Thanks for your help. Anne-Sophie -- View this message in context: http://r.789695.n4.nabble.com/function-lm-get-back-the-coefficient-tp3696109p3696109.html Sent from the R help mailing list archive at Nabble.com.
On Tue, Jul 26, 2011 at 4:21 PM, ascoquel <ascoquel at yahoo.fr> wrote:> Hi, > > I've done a linear fit on my data and I would like to get back the a (time) > coefficient ... > > mod<-lm(res_sql2$Lx0x~0+time) > result<-data.frame() > result<-coef(mod) > print("result") > print(result) > [1] "result" > ? ? ?time > 0.02530191 > > But I would like just the value 0.02530191 ... I tried result$time but it > doesn't work ...It is 'just the value'. It happens to be in a named vector with a length of 1. You can do anything to it that you want to do with any other number. Try result * 2, or sqrt(result). If it really annoys you, try names(result)=NULL to get rid of the name. Barry
Will: result$coef[[2]] Give you want you want? Jeremy On 26 July 2011 08:21, ascoquel <ascoquel at yahoo.fr> wrote:> Hi, > > I've done a linear fit on my data and I would like to get back the a (time) > coefficient ... > > mod<-lm(res_sql2$Lx0x~0+time) > result<-data.frame() > result<-coef(mod) > print("result") > print(result) > [1] "result" > ? ? ?time > 0.02530191 > > But I would like just the value 0.02530191 ... I tried result$time but it > doesn't work ... > > Thanks for your help. > Anne-Sophie > > -- > View this message in context: http://r.789695.n4.nabble.com/function-lm-get-back-the-coefficient-tp3696109p3696109.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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. >
It was result[[1]] I have no intercept Thanks !!! -- View this message in context: http://r.789695.n4.nabble.com/function-lm-get-back-the-coefficient-tp3696109p3696230.html Sent from the R help mailing list archive at Nabble.com.
Possibly Parallel Threads
- Constraint on coefficient when fitting with lm, glm etc ...
- syntax to restrict coefficient in lm()
- problem to get coefficient from lm()
- Coefficient names when using lm() with contrasts
- lm, coefficient 'not defined because of singularities'? What does this mean?