For those who accidentally stumble upon this - if you want the index vector to be based on possibly zero length, and not on another vector, you can safely use seq(1, length.out = L) , where L can be any non-negative integer. This will give you integer(0) if L == 0 and 1:L otherwise.
Of course, the other solutions given here are more concise if L == length(something) , but I had a problem when it was not, so I decided to write it for posterity.
Also seq(1, length.out = L) can be abbreviated as seq_len(L) , which according to ?seq is faster.
source share