[R] List or matrix of object
jim holtman
jholtman at gmail.com
Tue Oct 12 17:49:51 CEST 2010
You probably need to review the Intro to R to understand indexing:
> f1 <- function(x) sqrt(x%*%x);
> f2 <- function(x) (2*x+1);
> L <- list()
> L[[1]] <- f1
> L[[2]] <- f2
> L # contains the objects
[[1]]
function (x)
sqrt(x %*% x)
[[2]]
function (x)
(2 * x + 1)
> L[[1]](3) # now call the functions in the list
[,1]
[1,] 3
> L[[2]](42)
[1] 85
>
On Tue, Oct 12, 2010 at 11:17 AM, Filoche <pmassicotte at hotmail.com> wrote:
>
> 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list