[R] multiple return
ONKELINX, Thierry
Thierry.ONKELINX at inbo.be
Fri Jun 22 13:27:35 CEST 2007
Put the return values in a vector or list
somma <- function (a, b) {
c <- a+b
return (c(a = a, b = b, c = c))
}
somma(5,7)
a b c
5 7 12
somma <- function (a, b) {
c <- a+b
return (list(a = a, b = b, c = c))
}
somma(5,7)
$a
[1] 5
$b
[1] 7
$c
[1] 12
Cheers,
Thierry
------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
www.inbo.be
Do not put your faith in what statistics say until you have carefully
considered what they do not say. ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney
> -----Oorspronkelijk bericht-----
> Van: r-help-bounces op stat.math.ethz.ch
> [mailto:r-help-bounces op stat.math.ethz.ch] Namens Manuele Pesenti
> Verzonden: vrijdag 22 juni 2007 12:38
> Aan: r-help op stat.math.ethz.ch
> Onderwerp: [R] multiple return
>
> Dear User,
> what's the correct way to obtain a multiple return from a function?
>
> for example creating the simple function:
>
> somma <- function (a, b) {
> c <- a+b
> return (a, b, c)
> }
>
> when I call it, it runs but returns the following output:
>
> > somma(5, 7)
> $a
> [1] 5
>
> $b
> [1] 7
>
> $c
> [1] 12
>
> Warning message:
> return multi-argomento sono deprecati in: return(a, b, c)
>
> i.e. multi-return is deprecated...
>
> thanks a lot
> best regards
> Manuele
>
> --
> Manuele Pesenti
> manuele op inventati.org
> amicogodzilla op jabber.linux.it
> http://mpesenti.polito.it
>
> ______________________________________________
> R-help op 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
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list