[R] Lists with NULL entries

Greg Snow Greg.Snow at imail.org
Tue Sep 21 20:55:20 CEST 2010


Why not just do:

lst2 <- c(list(NULL), lst)



-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Peter Langfelder
> Sent: Monday, September 20, 2010 9:52 PM
> To: r-help
> Subject: Re: [R] Lists with NULL entries
> 
> 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
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list