[R] Problem with unlist

Susan Gruber sgruber at berkeley.edu
Tue Sep 28 23:01:31 CEST 2010


I suspect the problem is that table() is not displaying the correct
length.  Try
  table(n, useNA="ifany")

--Susan


>Message: 75
>Date: Mon, 27 Sep 2010 11:41:24 -0700
>From: Henrik Bengtsson <hb at stat.berkeley.edu>
>To: Ben Bolker <bbolker at gmail.com>
>Cc: r-help <r-help at stat.math.ethz.ch>
>Subject: Re: [R] Problem with unlist
>Message-ID:
>        <AANLkTi=hYM1y25uc_fKdxh5Qde14v3K_a5Ub6azgjWFO at mail.gmail.com>
>Content-Type: text/plain; charset=ISO-8859-1

>On Mon, Sep 27, 2010 at 5:27 AM, Ben Bolker <bbolker at gmail.com> wrote:
>> Luis Felipe Parra <felipe.parra <at> quantil.com.co> writes:
>>
>>>
>>> ?Hello, I am trying to unlist a list, which is attached, and I am
having the
>>> problem that when I unlist it the number of elements changes from 5065 to
>>> 5084
>>>
>>> ?> x <- lapply(SumaPluvi, FUN="[", 1);
>>> > n <- sapply(x, FUN=length);
>>> > print(table(n));
>>> n
>>> ? ?1
>>> 5065
>>> > print(which(n != 1));
>>> integer(0)
>>> > length(unlist(lapply(SumaPluvi, FUN="[", 1)))
>>> [1] 5081
>>> >
>>>
>>> I dont now why, but when I unlist it the number of elements changes from
>>> 5065 to 5084 even if there is no list element with length greater than
one.
>>> Do you know what can be happening?
>>>
>>
>> ?We probably won't be able to get farther without a reproducible
>> example. ?One brute-force way of finding the problem is by bisection:
>> i.e., try the first and last halves of your list separately, and see
>> if either one individually shows a similar problem. ?Proceed recursively
>> until you localize the problem ...

>...and as alternative, my most recent post did contain an updated code
>snippet that is likely to find list elements generating more than one
>value.

/Henrik



More information about the R-help mailing list