How can I create a list of size n? For example, lines = read.table(filename, sep="\n") how would I create a list called linesCopy that is of the size of lines?
I tried something like linesCopy <- [[length(lines)]] but this throws unexpected token [[
A list is just a vector, you can create a list of any size using vector().
For example, a list of size 4:
vector("list", 4)
[[1]]
NULL
[[2]]
NULL
[[3]]
NULL
[[4]]
NULL
Or, specific in your case, a list named linesCopy with the same size as the length of lines:
linesCopy <- vector("list", length(lines))
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