[R] swapping rows with columns

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Tue Mar 12 17:09:14 CET 2002


Arne Mueller <a.mueller at icrf.icnet.uk> writes:

> Hello,
> 
> I've read in a data file as a frame and now I'd like the columns to be
> rows and the rows to be columns. What's the easiest way to do this in R?
> 
> > class(d)
> [1] "data.frame"
> 
> > rownames(d)
> [1] "98x101" "40x98"  "30x40"  "0x30"  
> 
> > colnames(d)
>  [1] "H..sapiens"      "C..elegans"      "D..melanogaster"
> "S..cerevisiae"  
>  [5] "E..coli"         "M..tuberculosis" "B..subtilis"    
> "V..cholerae"    
>  [9] "A..pernix"       "P..horikoshii"   "M..jannaschii"  
> "A..aeolicus"    
> [13] "H..pylori"       "M..genitalium"  
> 
> Do I have to recunstruct the new frame or matrix manually?

as.data.frame(t(d))

or just t(d) if you don't care that it becomes a matrix in the process.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list