Adding new elements to list R -


i'm having trouble updating list. create list:

>list1 <- list(c(1,2,3),c(4,5),c(6,7,8)) list1 

and get:

[[1]] [1] 1 2 3  [[2]] [1] 4 5  [[3]] [1] 6 7 8 

and want append additional slice. try:

list2 <- list(list1,c(9,10,11)) list2 

and get:

[[1]] [[1]][[1]] [1] 1 2 3  [[1]][[2]] [1] 4 5  [[1]][[3]] [1] 6 7 8   [[2]] [1]  9 10 11     

but wanted was:

[[1]] [1] 1 2 3  [[2]] [1] 4 5  [[3]] [1] 6 7 8  [[4]] [1]  9 10 11 

if there's solution computationally efficient, great. process going repeat on >800k slices.

i accept alternative using list() function create nested data structure.

c(list1,list(c(9,10,11))) # [[1]] # [1] 1 2 3 #  # [[2]] # [1] 4 5 #  # [[3]] # [1] 6 7 8 #  # [[4]] # [1]  9 10 11 

we can use c concatenate 2 lists.


Comments