Problems Using Double Lists

I had problems trying to implement a double list in R. If one subscription is initialized with only one element, then after I tried to add more elements, I get an error message:

more items added than there are to replace

Here is an example:

# # This is OK # a <- list() a[["elem1"]][["elem2"]] <- c(10,20) a[["elem1"]][["elem2"]] <- c(a[["elem1"]][["elem2"]], c(30,40)) 

And this is the result:

 > a $elem1 $elem1$elem2 [1] 10 20 30 40 

But,

 # # This is giving error: # a <- list() a[["elem1"]][["elem2"]] <- c(10) a[["elem1"]][["elem2"]] <- c(a[["elem1"]][["elem2"]], c(30,40)) Error in a[["elem1"]][["elem2"]] <- c(a[["elem1"]][["elem2"]], c(30, 40)) : more elements supplied than there are to replace 

and this is the result:

 > a $elem1 elem2 10 

I would appreciate any help.

+5
source share

All Articles