[R] How to return more than one variable from function

Julien Barnier jbarnier at ens-lsh.fr
Fri Apr 20 13:46:27 CEST 2007


Hi,

> I have written a function which computes variance, sd,
> r^2, R^2adj etc. But i am not able to return all of
> them in return statement.

You can return a vector, or a list.

For example :

func <- function() {
  ...
  result <- list(variance=3, sd=sqrt(3))
  return(result)  # you can omit this
}
 
a <- func()
a$variance
a$sd      

HTH,

Julien

-- 
Julien Barnier
Groupe de recherche sur la socialisation
ENS-LSH - Lyon, France



More information about the R-help mailing list