Rle factors, table and empty levels
0
0
Entering edit mode
@valerie-obenchain-4275
Last seen 2.4 years ago
United States
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
IRanges IRanges • 1.4k views
ADD COMMENT

Login before adding your answer.

Traffic: 339 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6