# Re: [R] Function -return value

From: Christophe Pallier <christophe_at_pallier.org>
Date: Tue, 19 Jun 2007 18:46:12 +0200

First, to return several values from your function 'parameter', you can use a list:

parameter <- function (...) {
...
list(alpha=alpha,beta=beta,para=para,parab=parab) }

Then, you may use:

sapply(split(variable,list(a,b)), parameter)

(tapply also works but return a matrix of lists)

Christophe Pallier

On 6/19/07, livia <yn19832_at_msn.com> wrote:
>
>
> Hi, I am trying to write a function with the following codes and I would
> like
> it to return the values for "alpha
> beta para parab " seperately. Then I would like to use this funstion for
> "variable" with factor "a" and "b". But the result turns out to be a
> matrix
> with element like "Numeric,2" ... I guess they are just the values for
> "parab", and we can not even see the two parameters in parab.
>
>
> parameter <- function(v) {
> v1 <- v[v>mean(v)+0.5*sd(v)]
> v2 <- v[v<mean(v)-0.5*sd(v)]
> alpha=min(v1)
> beta=max(v2)
> para <- fitgpd(v1,alpha, method="pwmu")\$param
> parab <- fitgpd((-v2), (-beta), method="pwmu")\$param
> v1.fit <- qgpd(ppoints(v1, a=0.5), alpha, para[1], para[2])
> v2.fit <- qgpd(ppoints((-v2), a=0.5), (-beta), para[1], para[2])
> alpha
> beta
> para
> parab
>
> }
>
> tapply(variable, list(a, b),parameter)
>
>
> I would be grateful if anyone can give me some advice. Many thanks
> --
> View this message in context:
> http://www.nabble.com/Function--return-value-tf3947134.html#a11197159
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

```--
Christophe Pallier (http://www.pallier.org)

[[alternative HTML version deleted]]

______________________________________________
R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help