[R] Lists with NULL entries

Peter Langfelder peter.langfelder at gmail.com
Tue Sep 21 05:52:14 CEST 2010


Hi Joshua,

thanks, I came up with that solution myself after a bit of thinking.
Normally I wouldn't worry about NULL components of lists, but dimnames
is a list and often some components are null and is therefore a bit
tricky to manipulate...

Peter

On Mon, Sep 20, 2010 at 7:39 PM, Joshua Wiley <jwiley.psych at gmail.com> wrote:
> Sorry, that was a really half-hearted reply.  This will create a new
> list that is the old list shifted down (and should be much faster than
> the for loop too).
>
> lst <- list(NULL,2)
> lst2 <- vector("list", length(lst) + 1)
> lst2[2:length(lst2)] <- lst
> lst
> lst2
>
> If you really need to use a for loop, maybe try filling it with NAs
> instead of NULLs?
>
> Josh



More information about the R-help mailing list