Grokbase Groups R r-help March 2002
FAQ
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?

thanks for help,

Arne

--
Arne Mueller
Biomolecular Modelling Laboratory
Imperial Cancer Research Fund
44 Lincoln's Inn Fields
London WC2A 3PX, U.K.
phone : +44-(0)207 2693405 | fax :+44-(0)207-269-3534
email : a.mueller at icrf.icnet.uk | http://www.bmm.icnet.uk
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

Search Discussions

  • Peter Dalgaard BSA at Mar 12, 2002 at 4:09 pm

    Arne Mueller <a.mueller@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
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
  • Arne Mueller at Mar 12, 2002 at 4:22 pm

    ripley at stats.ox.ac.uk wrote:
    t(as.matrix(d))
    Yes, that's what I was looking for. Thanks for your quick replys. For me
    as an R
    newbe is that I don't find the appropiate functions and objects in the
    R-documentation.
    I'm mainly using the html pages with the built-in java-script search
    engine to lookup functions etc. Unfortunately the keyword 'transform' or
    'swap' didn't come uo with the 't' function.

    Sorry if most of my questions are trivial or with 'obvious' answers.
    It's just a little bit hard at the beginning to make my way through the
    documentation ...

    thanks very much for all your help,

    Arne
    On Tue, 12 Mar 2002, Arne Mueller wrote:

    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?
    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    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
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
  • Uwe Ligges at Mar 12, 2002 at 4:25 pm

    Arne Mueller wrote:
    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?

    t(x)

    Uwe
    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    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
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
  • Jonathan Baron at Mar 12, 2002 at 5:01 pm

    On 03/12/02 15:41, Arne Mueller wrote:
    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?
    No. The t() function flips the rows and columns of a matrix. It
    also works on a data frame that can be coerced into a matrix, but
    it yields a matrix. So you can say

    d2 <- as.data.frame(t(d))

    --
    Jonathan Baron, Professor of Psychology, University of Pennsylvania
    Home page: http://www.sas.upenn.edu/~baron
    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    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
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupr-help @
categoriesr
postedMar 12, '02 at 3:41p
activeMar 12, '02 at 5:01p
posts5
users4
websiter-project.org
irc#r

People

Translate

site design / logo © 2017 Grokbase