[R] Odp: changing the number of elements in a list

From: Petr PIKAL <petr.pikal_at_precheza.cz>
Date: Wed, 09 Jun 2010 16:01:56 +0200

Hi

one option is to create an empty list with

my.list <- vector("list", n)

where n is number of elements in list. Then you can populate each element by

my.list[[x]] <- something

where x can be number or

my.list[x] <-something

where x is numeric vector

Regards
Petr

r-help-bounces_at_r-project.org napsal dne 09.06.2010 15:46:09:

> I would like to have a list where each element is a matrix, for example:
>
> my.list <- list(matrix(0, ncol=3, nrow=3),
> matrix(0, ncol=3, nrow=3),
> matrix(0, ncol=3, nrow=3))
>
> The problem is, I would like to be able to change automatically the
number of
> elements in the list (not only three as in the above example).
>
> That is, the instruction creating the list would be a part of a function
that
> has an inputing parameter stating how many elements (matrices) the list
has.
>
> I have tried several things, but none worked.
> However, this seems to be a rather simple problem.
> All help is welcome!
>
> LBA
>
> ______________________________________________
> 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.



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. Received on Wed 09 Jun 2010 - 14:04:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 Jun 2010 - 14:40:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive