Hmm... do something like that, no need to change the global option (I used a
named vector instead of a list, it's more convenient):

eg <- function(x, digits=4) {
xbar <- mean(x)
sdx <- sd(x)
value <- c(xbar, sdx)
names(value) <- c("Mean of X", "SD of X")
print(round(value,digits));
return(invisible(value))}


On Fri, Mar 12, 2010 at 8:14 AM, Joshua Wiley <jwiley.ps...@gmail.com>wrote:

> Dear R users,
>
> I am stuck trying to figure out how to make a function return one
> value and print another.  Here is an example function:
>
> ##################
> eg <- function(x, digits=4) {
> xbar <- mean(x)
> sdx <- sd(x)
> value <- list(xbar, sdx)
> names(value) <- c("Mean of X", "SD of X")
> return(value)}
> ##################
>
> My current "solution" has been to round the variables before putting
> them into the list.  Since it can go up to 22 digits, this is fine for
> my basic needs.  However, my goal is for assignments to have full
> precision, but the screen printout to be rounded to "digits".  I have
> looked through ?return ?cat ?print.
>
> Can anyone suggest where I can learn how to do this (help pages, books,
> etc.)?
>
> Thanks in advance,
>
>
> Josh
>
> --
> Joshua Wiley
> Senior in Psychology
> University of California, Riverside
> http://www.joshuawiley.com/
>
> ______________________________________________
> R-help@r-project.org 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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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.

Reply via email to