[BioC] Rle factors, table and empty levels
Valerie Obenchain
vobencha at fhcrc.org
Wed Nov 7 02:01:39 CET 2012
Pete,
Thanks for the bug report. This is fixed in IRanges 1.17.11.
Note that the data inside the rle must be a factor. Adding levels to an
Rle after the fact doesn't create a factor-Rle.
x = Rle(c(2,3,1,2,3,2),rep(2,6))
levels(x) = as.character(0:5)
This is a numeric-Rle with no levels.
> x
numeric-Rle of length 12 with 6 runs
Lengths: 2 2 2 2 2 2
Values : 2 3 1 2 3 2
> table(x)
1 2 3
2 6 4
The same is true for a numeric vector. table() on a non-factor argument
will drop unused levels.
v <- rep(c(2,3,1,2,3,2), each=2)
levels(v) <- 0:5
> table(v)
v
1 2 3
2 6 4
If we create a factor-Rle, table() will retain all levels.
x_f = Rle(factor(rep(c(2,3,1,2,3,2), each=2), levels=0:5))
> x_f
factor-Rle of length 12 with 6 runs
Lengths: 2 2 2 2 2 2
Values : 2 3 1 2 3 2
Levels(6): 0 1 2 3 4 5
> table(x_f)
0 1 2 3 4 5
0 2 6 4 0 0
Valerie
On 10/29/2012 08:13 PM, Valerie Obenchain wrote:
> Thanks Pete. I'll look into it.
>
> Valerie
>
> On 10/29/12 14:28, Peter Haverty wrote:
>> Dear Group,
>>
>> table(Rle) seems to ignore empty levels.
>>
>> x = Rle(c(2,3,1,2,3,2),rep(2,6))
>> levels(x) = as.character(0:5)
>> table(x)
>> table(factor(as.numeric(x),levels=as.character(0:5)))
>>
>> I am using R 2.15.1 and IRanges 1.17.1.
>>
>> Regards,
>> Pete
>>
>> ____________________
>> Peter M. Haverty, Ph.D.
>> Genentech, Inc.
>> phaverty at gene.com
>>
>> _______________________________________________
>> Bioconductor mailing list
>> Bioconductor at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/bioconductor
>> Search the archives:
>> http://news.gmane.org/gmane.science.biology.informatics.conductor
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives:
> http://news.gmane.org/gmane.science.biology.informatics.conductor
More information about the Bioconductor
mailing list