[R] help on writing a function
Rui Barradas
ruipbarradas at sapo.pt
Sat Mar 23 12:49:05 CET 2013
Hello,
Try this one liner.
g2 <- 50 * prod(exp(-x*a))
identical(g, g2) # TRUE
Hope this helps,
Rui Barradas
Em 23-03-2013 11:27, Andras Farkas escreveu:
> Dear All
>
> If you could please help me with a solution on the following:
> we have:
>
> a <-matrix(c(1,2,3,4,5))
> x <-matrix(c(0.3,0.2,0.1,0.08,0.05))
> b <-50*exp(-x[1]*a[1])
> d <-b*exp(-x[2]*a[2])
> e <-d*exp(-x[3]*a[3])
> f <-e*exp(-x[4]*a[4])
> g <-f*exp(-x[5]*a[5])
>
> I would like to be able to calculate g with fewer steps, thought perhaps a function could do that?
>
> I apreciate your help,
>
> thanks
>
> Andras
> [[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