Search code examples
listrnullresizefill

How to expand a list with NULLs up to some length?


Given a list whose length <= N, what is the best / most efficient way to fill it up with trailing NULLs up to length (so that it has length N).

This is something which is a one-liner in any decent language, but I don't have a clue how to do it (efficiently) in a few lines in R so that it works for every corner case (zero length list etc.).


Solution

  • Let's keep it really simple:

    tst<-1:10 #whatever, to get a vector of length 10
    tst<-tst[1:15]