[R] Return one value, print another

Dieter Menne dieter.menne at menne-biomed.de
Fri Mar 12 09:43:06 CET 2010



Joshua Wiley-2 wrote:
> 
> I am stuck trying to figure out how to make a function return one
> value and print another.  Here is an example function:
> 
> .. see below
> My current "solution" has been to round the variables before putting
> 

The easiest way out, e.g. for a lecture, is to use options(digits=x), which
is global but can be reset. Otherwise, you could assign a class to your
returned output, and define print.myclass. Probably a bit too much work for
what you want to achieve. See, for example, the code of  print.htest.

Dieter

eg <- function(x, digits=4) {
  xbar <- mean(x)
  sdx <- sd(x)
  value <- list(xbar, sdx)
  names(value) <- c("Mean of X", "SD of X")
  value
}
options(digits=2)
eg(rnorm(10))

-- 
View this message in context: http://n4.nabble.com/Return-one-value-print-another-tp1590248p1590260.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list