[R] Problem with unlist

Luis Felipe Parra felipe.parra at quantil.com.co
Mon Sep 27 04:06:15 CEST 2010


 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?

Thank you

Felipe Parra



On Mon, Sep 27, 2010 at 8:05 AM, Henrik Bengtsson <hb en stat.berkeley.edu>wrote:

> x <- lapply(SumaPluvi, FUN="[", 1);
> n <- sapply(x, FUN=length);
> print(table(n));
> print(which(n != 1));
>
> My $.02
>
> /H
>
> On Sun, Sep 26, 2010 at 4:12 PM, Luis Felipe Parra
> <felipe.parra en quantil.com.co> wrote:
>  > Hello I want to unlist the attached element getting only the first
> element
> > in each element of the list. The last element of the list looks as this:
> >
> > [[5065]]
> > [[5065]]$Pluv3Meses
> > [1] 274.4
> > [[5065]]$PluvMesesMedio
> > [1] 378.2667
> > [[5065]]$Pluv2UltimosMeses
> > [1] 23.33333
> >
> > So I would like to get for each element of the list the element called
> > Pluv3Meses. The whole list has 5065 elements but when I try to unlist it
> I
> > am getting 5081 elements I don't know why:
> >
> >> length(unlist(sapply(SumaPluvi,"[",1)))
> > [1] 5081
> >
> > Does anybody know what can be happening?
> >
> > Thank You
> >
> > Felipe Parra
> >
>  > ______________________________________________
> > R-help en 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<http://www.r-project.org/posting-guide.html>
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
>


More information about the R-help mailing list