[R] Problem with unlist

Joshua Wiley jwiley.psych at gmail.com
Mon Sep 27 01:42:37 CEST 2010


Hi Felipe,

Could it be something like what happens in mylist2?

###########
mylist <- list(1:4, 2:5, 3:6)

mylist2 <- list(list(1:4, 11:14), 2:5, 3:6)

length(unlist(sapply(mylist, "[", 1)))
length(unlist(sapply(mylist2, "[", 1)))
###########


HTH,

Josh


On Sun, Sep 26, 2010 at 4:12 PM, Luis Felipe Parra
<felipe.parra at 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 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.
>
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list