I would like to ask if it is possible to add an element into a list.
For example the list
L <- vector("list", 2)
L[[1]] <- vector("list", 2)
I want to become
[[1]]
[[1]][[1]]
NULL
[[1]] # add an element and it becomes [[1]]
[[1]][[2]] [[1]][[2]][[3]]
NULL NULL
[[2]]
NULL
Thank you all, in advance
In your code for list “L”,
represents the first item in list
[[1]]and can be referenced byL[[1]][[1]].represents the second item in
[[1]]and can be referenced byL[[1]][[2]]. So, to add a new element into the list, you can just use:Personally, I find it much easier to work with named elements though, since keeping track of those brackets can be somewhat tedious.