[R] How to get the input of a function right?

Petr PIKAL petr.pikal at precheza.cz
Thu Mar 29 15:04:07 CEST 2012


Hi
> 
> 
> Hi Michael and Sarah,
>  
> Thank you for offering help. I finally managed to construct an example 
> with all essentials of my problem: 
>  
> x1<-c(1,2,3,4)
> x2<-c(2,3,4,5)
> x3<-c(3,4,5,6)
> x<-rbind(x1,x2,x3)
> time<-c(1,3,9)
> fit<-function(xx,t,tcc){slope <- coefficients(lm(log(xx) ~ 0 + t))[1]

You were quite close

fit<-function(xx,t,tcc){slope <- coefficients(lm(log(xx) ~ 0 + t))

Regards
Petr

> alpha<-slope-log(2)/tcc
> return(alpha)
> }
> alpha<-fit(x,time,20)
>  
> At the moment the function output 'alpha' is calculated for x
> (x1=1,x2=2,x3=3). I would like to get 'alphas' for all four rows of x 
> without using a for-loop. Is there any possibility to avoid a for-loop?
>  
> Thank you very much in advance,
> Stella
> 
> 
> Von: Sarah Goslee <sarah.goslee at gmail.com>
> An: R. Michael Weylandt <michael.weylandt at gmail.com> 
> CC: stella <dorotheabusse at yahoo.de>; r-help at r-project.org 
> Gesendet: 17:14 Donnerstag, 22.März 2012
> Betreff: Re: [R] How to get the input of a function right?
> 
> On Thu, Mar 22, 2012 at 11:55 AM, R. Michael Weylandt
> <michael.weylandt at gmail.com> wrote:
> > This is quite difficult without being able to see the function f .....
> >
> > Michael
> 
> I thought we had a fortune about telepathy, but I can't find it in the
> fortunes package.
> 
> Sarah
> -- 
> Sarah Goslee
> http://www.functionaldiversity.org
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.



More information about the R-help mailing list