[BioC] matrix row/column displayed as a list

Seth Falcon sfalcon at fhcrc.org
Tue Apr 10 19:23:33 CEST 2007


Daniel Brewer <daniel.brewer at icr.ac.uk> writes:
> Here is a reproducible list of commands to produce such a matrix.  It is
> probably very inefficient but I am new at this.

So cbind is documented to create these list-based matrices if given
lists as arguments instead of atomic vectors.  I certainly don't blame
you for not knowing this, it is a rather subtle detail.

I'm pretty sure the problem slips in here:

> #Average over those probes that share clone IDs for each platform
> tempo2 <- do.call("cbind",lapply(1:ncol(exprGPL1283),function(i)
> {
> listo <- split(exprGPL1283[,i],GPL1283Annot$REPORTER)
> tempo <- lapply(listo,function(x) {
> median(unlist(x),na.rm=T)
> })
> return(matrix(tempo))
> }))

Here lapply on listo returns a list and matrix of a list gives you the
weird list-based matrix object.  So you could try using sapply or
instead of calling matrix (not sure what the benefit of that is) you
could unlist.  Here's an untested idea:

tempo2 <- do.call("cbind",
                  lapply(1:ncol(exprGPL1283), function(i) {
                      listo <- split(exprGPL1283[ , i], GPL1283Annot[["REPORTER"]])
                      sapply(listo, function(x) {
                          median(unlist(x), na.rm=T)
                      })
                  }))


There is also something to be said here about debugging your own code
and process.  You could have likely solved your own problem had you
broken down your transformation into smaller steps and verified the
pieces as you went.

+ seth

-- 
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
http://bioconductor.org



More information about the Bioconductor mailing list