[R] ?? hmm ??

Thomas Lumley tlumley at u.washington.edu
Tue Sep 11 17:20:56 CEST 2001

On Mon, 10 Sep 2001 Gerard.Keogh at cso.ie wrote:

> 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?

Actually neither x nor m gets printed from within the function, because
you didn't ask R to print either of them.

The statement
means "Work out what x is". To print x you need
which means "Work out what x is and print the result"

The thing that is printed when you type mm(u) at the command line is not m
but mm(u). At the command line, only, a calculated value that isn't
assigned to any other variable will be printed.

at the command line means "Work out the value of mm(u)", and since it is
at the command line and the result is not assigned to anything it is printed.


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