Horje
r define nested empty list Code Example
r define nested empty list
rec.list <- function(len){
    if(length(len) == 1){
        vector("list", len)
    } else {
        lapply(1:len[1], function(...) rec.list(len[-1]))
    }
}
depth = c(1, # only one object
          2  # two objects
         )
my.list <- rec.list()

# The obtained structure is: 
## [[1]]
## [[1]][[1]]
## [[1]][[2]]

my.list<-lapply(my.list<-vector(mode = 'list',5),function(x) # 1st level with 5 objects
      x<-lapply(x<-vector(mode = 'list',3),function(x)       # 2nd level with 3 nested objects
      x<-vector(mode='list',2)))                             # 3rd level with 2 nested objects




R

Related
how to add random numbers randomly in a dataframe in r Code Example how to add random numbers randomly in a dataframe in r Code Example
r - remove scientific notations Code Example r - remove scientific notations Code Example
dplyr replace na Code Example dplyr replace na Code Example
R string ascii accents Code Example R string ascii accents Code Example
mode in r Code Example mode in r Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7