[R] List or matrix of object

Greg Snow Greg.Snow at imail.org
Tue Oct 12 17:52:29 CEST 2010


It is not clear exactly what you are trying to do, but this works:

f1 <- function(x) sqrt(x%*%x)
f2 <- function(x) {2*x+1}

L <- list();
L[[1]] = f1;
L[[2]] = f2;


Then you can do something like:

L[[2]](5)

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Filoche
> Sent: Tuesday, October 12, 2010 9:17 AM
> To: r-help at r-project.org
> Subject: [R] List or matrix of object
> 
> 
> Hi everyone.
> 
> Is it possible in R to create a matrix or a list (vector) or R object.
> For
> instance, I have
> 
> f1 <- function(x) sqrt(x%*%x);
> f2 <- function(x) (2x+1);
> 
> I would like to do something like
> 
> L <- List();
> L[1] = f1;
> L[2] = f2;
> 
> So, is there a way to create matrix or vector that can contains R
> object.
> 
> With regards,
> Phil
> --
> View this message in context: http://r.789695.n4.nabble.com/List-or-
> matrix-of-object-tp2992101p2992101.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list