Dera R users, 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. So how to return more than one variable from function. In C i used to return by pointers etc. is there any way like that. Thanks in advance.
use a 'list' as the return value containing the values you want
returned.
x<- function(){
.....
list(val1=a, val2=b, val3=c)
}
On 4/20/07, vinod gullu <vinodkgul at yahoo.com>
wrote:> Dera R users,
> 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.
> So how to return more than one variable from
> function. In C i used to return by pointers etc. is
> there any way like that.
>
> Thanks in advance.
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
?list ----- Original Message ---- From: vinod gullu <vinodkgul@yahoo.com> To: r-help@stat.math.ethz.ch Sent: Friday, April 20, 2007 5:00:45 PM Subject: [R] How to return more than one variable from function Dera R users, 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. So how to return more than one variable from function. In C i used to return by pointers etc. is there any way like that. Thanks in advance. ______________________________________________ R-help@stat.math.ethz.ch 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]]
Julien Barnier
2007-Apr-20 11:46 UTC
[R] How to return more than one variable from function
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