[R] ?? hmm ??

Philippe Grosjean phgrosje at ulb.ac.be
Tue Sep 11 10:19:13 CEST 2001


A function returns only a single result in R. A way to get several results
from a function is by using a list:

> mm <- function(u) {
+	x <- u$GDP
+	m <- mean(x)
+	res <- list(data=x, mean=m)
+	res
+ }

> a <- NULL
> a$GDP <- 1:10
> a.mm <- mm(a)
> a.mm$data
 [1]  1  2  3  4  5  6  7  8  9 10
> a.mm$mean
 [1] 5.5

All the best,

Philippe Grosjean


...........]<(({?<...............<?}))><...............................
 ) ) ) ) )	 __               	 __
( ( ( ( ( 	|__)              	|  _
 ) ) ) ) )	|   hilippe       	|__)rosjean
( ( ( ( ( 	Marine Biol. Lab., ULB, Belgium
 ) ) ) ) )	                  	 __
( ( ( ( ( 	|\  /|            	|__)
 ) ) ) ) )	| \/ |ariculture &	|__)iostatistics
( ( ( ( (
 ) ) ) ) )	e-mail: phgrosje at ulb.ac.be or phgrosjean at sciviews.org
( ( ( ( ( 	SciViews project coordinator (http://www.sciviews.org)
 ) ) ) ) )      tel: 00-32-2-650.29.70 (lab), 00-32-2-673.31.33 (home)
( ( ( ( (
 ) ) ) ) )      "I'm 100% confident that p is between 0 and 1"
( ( ( ( (                                  L. Gonick & W. Smith (1993)
 ) ) ) ) )
.......................................................................


-----Message d'origine-----
De : owner-r-help at stat.math.ethz.ch
[mailto:owner-r-help at stat.math.ethz.ch]De la part de Gerard.Keogh at cso.ie
Envoye : lundi 10 septembre 2001 17:18
A : r-help at lists.r-project.org
Objet : [R] ?? hmm ??


Hello again!
thanks to all who helped with overlay plots - v.  easy in the end.

Anyway, another new(ba)bee type question - the gurus will cringe I'm sure!

Q. simple R function
mm <- function (u) {
  x <- u$GDP
  x
  m <- mean(x)
  m
}

When the function is called the vector "x" does not get printed from within
the function, but the mean value "m" does, why?
I think it's probably to do with scoping but don't really know.
The vector "x" can of course be printed with the print function so there no
problem seeing it for program debugging etc.

Thanks in advance.

Gerard Keogh

The information in this email, and any attachments transmitted with it, are
confidential
and are for the intended recipient only. If you receive this message in
error, please
notify us via postmaster at cso.ie.

To see the latest figures from the CSO go to http://www.cso.ie

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list