Here is a code (also see comments in code):
library(rlist)
lwa_res_lst <- vector(mode = "list", length = 1) # Create empty list. Unfortunatly with this method I cannot create list with 0 length.
current_res <- 1
lwa_res_lst <- list.append(lwa_res_lst, current_res) # Append the element at the end of the list.
My question is: How to initially create empty list to which after can be appended an element with list.append() at position 1?
We can just do assignment
lwa_res_list[[1]] <- current_res
In the OP's code, if the list was initialized as
lwa_res_lst <- list()
Or using OP's code
lwa_res_lst <- vector(mode = "list", length = 0)
the code should work
lwa_res_lst <- list.append(lwa_res_lst, current_res)
lwa_res_lst
#[[1]]
#[1] 1
current_res <- 1 #any number you want for list
lwa_res_lst <- vector(mode = "list", length = current_res)
lwa_res_lst
class(lwa_res_lst)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With