[BioC] unlist changes the length?

Robert Gentleman rgentlem at jimmy.harvard.edu
Mon Jul 5 22:00:19 CEST 2004


On Mon, Jul 05, 2004 at 11:49:07AM -0700, Irene Li wrote:
> Hi bioconductor users,
> 
> I am learning bioconductor by following the on-line short courses. This was 
> what happened when I tried some code in "Differential expression"
> >library(annotate)
> >library(hgu95av2)
> >chr <- getCHR(geneNames(ALLSub), "hgu95av2")
> Error: couldn't find function "getCHR"
> >chr <- mget(geneNames(ALLSub), env=hgu95av2CHR)
> >ll <- getLL(geneNames(ALLSub), "hgu95av2")
> >ll.chr <- tapply(chr, ll, unique)
> Error in unique.default(X[[as.integer(1)]], ...) :
>         unique() applies only to vectors
> >ll.chr <- tapply(unlist(chr), ll, unique)
> Error in tapply(unlist(chr), ll, unique) :
>         arguments must have same length
> >length(chr)
> [1] 2400
> >length(ll)
> [1] 2400
> >length(unlist(chr))
> [1] 2408
> >
> 
> Is this caused by a bug in "unlist" like an unaccessable link in google 
> search said, or I have done something wrong here? how can I solve this 
> problem?

 No, it is not a bug in unlist. If you have multiple values in one
 (or more) of the list elements then the resulting *vector* is
 longer. For other hash tables (those that encode GO or PubMed
 relationships) the effect is much more dramatic. Now, you might think
 that all genes are annotated to only one chromosome - but that is in
 fact not true. It is pretty straightforward to identify those genes
 with multiple annotations - and you must then make some decision
 about what you want to do.

 Best,
   Robert

ps:
> l1 = list(a=1:3, b=4:7)
> unlist(l1)
a1 a2 a3 b1 b2 b3 b4 
 1  2  3  4  5  6  7 
> length(l1)
[1] 2


> 
> Thanks.
> 
> Irene
> 
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://www.stat.math.ethz.ch/mailman/listinfo/bioconductor

-- 
+---------------------------------------------------------------------------+
| Robert Gentleman                 phone : (617) 632-5250                   |
| Associate Professor              fax:   (617)  632-2444                   |
| Department of Biostatistics      office: M1B20                            |
| Harvard School of Public Health  email: rgentlem at jimmy.harvard.edu        |
+---------------------------------------------------------------------------+



More information about the Bioconductor mailing list