Re: [R] Lists with NULL entries

2010-09-21 Thread Greg Snow
alf 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

Re: [R] Lists with NULL entries

2010-09-20 Thread Peter Langfelder
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

Re: [R] Lists with NULL entries

2010-09-20 Thread Joshua Wiley
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, may

Re: [R] Lists with NULL entries

2010-09-20 Thread Joshua Wiley
Hello Peter, This is because assigning a value of NULL removes that element of the list. I am not quite sure what the reference for that is. I remember reading it in the documentation once though. I looked through ?list to no avail. At any rate, to avoid it, you would have to assign something

[R] Lists with NULL entries

2010-09-20 Thread Peter Langfelder
Hello, I encountered a weird problem. Consider the following code that takes a list "lst" and shifts all elements one index up (for example, to make space for a new first element): lst = list(1,2) ll = length(lst); for (i in ll:1) lst[[i+1]] = lst[[i]]; lst If you run it, you get the expected