[R] allocation/initialization of arrays/lists

John Kane jrkrideau at yahoo.ca
Sun Jul 5 20:22:42 CEST 2009


Try 
mylist <- NULL

and then just assign the subsets to each element of the list

mylist[[1]] <- data1[,1]

as an example

--- On Sun, 7/5/09, zrl <zrl1974 at gmail.com> wrote:

> From: zrl <zrl1974 at gmail.com>
> Subject: [R] allocation/initialization of arrays/lists
> To: r-help at stat.math.ethz.ch
> Received: Sunday, July 5, 2009, 1:58 PM
> Dear list,
> 
> I have a question regarding how to allocate or initialize
> the proper type of
> the arrays or lists.
> 
> I have a for loop, each iteration, I want it to assign a
> subset of a data
> frame to an element of an array or list.
> However, I am wondering how I should initialize or allocate
> the empty array
> or list so that it has the same number of the elements as
> the subsets I am
> going to assign and also make the data type is compatible
> to the subset I am
> going to assign to it.
> It should look like this:
> 
> #initialize or allocate.   ( I don't know
> how to)
> { some codes: initialize an array or list (which one is
> better?) with "n"
> elements}
> 
> #"for" loop for assigning a subset of a large data frame to
> the elements of
> the array or list (which on is better?)
> for (i in 1: n){
> array[i] <- df[df$V1==A[i],]
> }
> 
> 
> 
> 
> Thanks.
> 
> ZRL
> 
>     [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.
> 


      __________________________________________________________________
Ask a question on any topic and get answers from real people. Go to Yahoo! Answer



More information about the R-help mailing list