I want to pre allocate a list containing lists of different length. The list will contain N rows and every row should contain another list with a specified length from another vector. It will look like this :
[[668]]
[1] 5096075
[[669]]
[1] 904607131
[[670]]
[1] 475127.3 430573.5 9046074.9
[[671]]
[1] 475121231237.3
[[672]]
[1] 0
[[673]]
[1] 43051273.5
[[674]]
[1] 41231230573.5
[[675]]
[1] 97304.1
With the length of the list in the list is there any way to preallocate the space? The way its done now is to expand the list every time i loop it which takes alot of time
If lengths
is your vector of lengths for each of the sub-lists then you can do:
lengths <- 1:10
lapply(lengths, vector, mode="list")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.