[R] multiple return values and optimization

Gabor Grothendieck ggrothendieck at gmail.com
Sat Jun 10 03:19:00 CEST 2006


optimize will preserve attributes so try this:

f <- function(x) structure(x^2, cubed = x^3)
optimize(f, c(-1, 1))

On 6/9/06, paul sorenson <sourceforge at metrak.com> wrote:
> I have a function (masheff) which returns a value which I can optimize
> no problem, eg:
>
> optimize(masheff, c(15,30), maximum=TRUE, m_gd=5.13, v_tot=41, e_c=1.0)
>
> I would like masheff() to return multiple values say as a list with
> named elements like so:
>
> v = masheff(...)
> v$eff
> v$extract
> etc
>
> Is there a simple way to do this in an optimize context or would I need
> to set some global variables and inspect them afterwards?
>
> ______________________________________________
> R-help at 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
>



More information about the R-help mailing list