[BioC] help with transpose

Sean Davis sdavis2 at mail.nih.gov
Tue Oct 18 13:27:13 CEST 2005


On 10/18/05 7:06 AM, "Alberto Goldoni" <alberto.goldoni at eurogene.org> wrote:

> Dear friends,
> 
>           I have a problem:
> 
> When I read a file with:
> 
>           tmp <- read.table("tottimecourseR.txt", sep="\t", header=F,
> na.strings = "")
> 
> all work fine:
> 
>           names(tmp)
> [1] "V1"   "V2"   "V3"   "V4"   "V5"   "V6"   "V7"   "V8"   "V9"
> "V10"  "V11"  "V12"  "V13"  "V14"  "V15"  "V16"  "V17"  "V18"  "V19"
> "V20"  "V21"
> 
> tmp[5,1:10]
>   V1   V2   V3   V4   V5   V6   V7   V8   V9  V10
> 5 1.11 0.81 0.94 0.87 0.75 0.62 1.19 0.48 0.76 0.76
> 
> 
> but if I make the transposition of tmp:
> 
> tmp.t<-t(tmp)
> 
> I obtain the numbers with "":
> 
> 1       2       3       4       5       6       7       8       9
> 10      11      12      13
> " 7.25" " 0.30" "-0.20" " 0.82" " 1.11" " 1.81" "-0.12" "-2.22" " 1.51"
> " 1.11" " 4.15" " 3.84" " 1.66"

Why the "" around numbers?  Read.table produces a data.frame, which is NOT
the same as a matrix.  In particular, data.frames can hold mixtures of
different data types (like character and numeric, for example).  Matrices,
on the other hand, can hold only one data type.  Why does this matter?
Because from the help for t(), you can see that whatever is passed to t() is
first coerced to a matrix.  If there are mixed types in the original
data.frame, tmp, then these data will all be coerced to the same type on
conversion to matrix; it looks like all the data were coerced to type
character.  

If you are going to do the transpose, you will need to make it into a
data.frame after the transpose, or transpose only the numeric part of the
original data.frame.


> and 
>> names(tmp.t)
> NULL
> 
> How can do to obtain:
> 
>> names(tmp.t)
> "gene1" "gene2" "gene3"                                    "geneN"

As far as I can see, you will need to assign the names yourself.  See
?colnames for how to do this.  But something like:

colnames(tmp.t) <- genenames

where genenames contains all of the genenames.

Hope this helps.

Sean



More information about the Bioconductor mailing list