Re: [R] Problem with unlist
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 h...@stat.berkeley.edu To: Ben Bolker bbol...@gmail.com Cc: r-help r-h...@stat.math.ethz.ch Subject: Re: [R] Problem with unlist Message-ID: aanlkti=hym1y25uc_fkdxh5qde14v3k_a5ub6azgj...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 On Mon, Sep 27, 2010 at 5:27 AM, Ben Bolker bbol...@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 __ R-help@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.
Re: [R] Problem with unlist
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 ... __ R-help@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.
Re: [R] Problem with unlist
On Mon, Sep 27, 2010 at 5:27 AM, Ben Bolker bbol...@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 __ R-help@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. __ R-help@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.
[R] Problem with unlist
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.3 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@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.
Re: [R] Problem with unlist
My guess is that some of the Pluv3Meses elements have more than one value. Have you checked your data to see if this is the case? On Sun, Sep 26, 2010 at 7:12 PM, Luis Felipe Parra felipe.pa...@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.3 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@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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@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.
Re: [R] Problem with unlist
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.pa...@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.3 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@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/ __ R-help@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.
Re: [R] Problem with unlist
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.pa...@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.3 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@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. __ R-help@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.
Re: [R] Problem with unlist
x - lapply(SumaPluvi, FUN=[, 1); y - lapply(x, FUN=unlist); # == n - sapply(y, FUN=length); print(table(n)); print(which(n != 1)); /Henrik On Sun, Sep 26, 2010 at 7:02 PM, Luis Felipe Parra felipe.pa...@quantil.com.co wrote: Henrik, thank you for your help, but I tried your code, and this is what I get 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 apparently the problem is still there if I use lapply, I dont now why, but when I unlist it the number of elements changes from 5065 to 5084 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 h...@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.pa...@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.3 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@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. __ R-help@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.
Re: [R] Problem with unlist
Henrik, thank you for your help, but I tried your code, and this is what I get 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 apparently the problem is still there if I use lapply, I dont now why, but when I unlist it the number of elements changes from 5065 to 5084 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 h...@stat.berkeley.eduwrote: 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.pa...@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.3 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@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@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.
[R] Problem with unlist
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 h...@stat.berkeley.eduwrote: 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.pa...@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.3 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@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@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.