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.).

Answers


Let's keep it really simple:

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

Try this :

> l = list("a",1:3)
> N = 5
> l[N+1]=NULL
> l
[[1]]
[1] "a"

[[2]]
[1] 1 2 3

[[3]]
NULL

[[4]]
NULL

[[5]]
NULL

>

Need Your Help

How to properly clamp 360 degrees overlap?

unity3d camera unityscript quaternions euler-angles

I have a camera script where if my character is rotating, the camera rotates too. However, the camera can also be rotated my the mouse pointer. This movement is restricted by a specific set of given

What is the difference between an OS and a Framework?

frameworks operating-system azure

I recently posted a question about Azure... is it really an OS? I understand the technical details, and I got a lot of fuzzy answers... I really want to know... what do you think is the difference