Grokbase Groups R r-help October 2010
FAQ
Hellow!

I am replicating the example givien in "Reshaping Data with the
reshape Package" (http://www.jstatsoft.org/v21/i12 - see "download"
link on the right), p. 2-3.

library(reshape)
data(smiths)
str(smiths)

The text says: "If you specify only one of measured and identifier
variables, melt assumes that all the other variables are the OTHER
sort:"
Hence, the result of the following 5 lines should be identical:

melt.data.frame(smiths, id = c("subject", "time"), measured = c("age",
"weight","height"))
melt.data.frame(smiths, id = c("subject", "time"))
melt.data.frame(smiths, id = 1:2)
melt.data.frame(smiths, measured = c("age", "weight", "height"))
melt.data.frame(smiths) # If you do not specify them
explicitly, melt will assume that any factor or character variables
are id variables


However, only the first 3 lines produce the same result.
I am especially surprised why line 4 uses "time" as a measured
variable, while it should be clear to reshape that "time" is NOT a
measured variable?


Thank you!
--
Dimitri Liakhovitski
Ninah Consulting
www.ninah.com

Search Discussions

  • Ista Zahn at Oct 5, 2010 at 4:17 pm
    Hi Dimitri,
    The argument names may have changed. Notice that

    melt.data.frame(smiths, measured = c("age", "weight", "height"))

    gives a message saying "Using subject as id variables". This is
    because measured variables need to be specified as measure.vars (or an
    abbreviation of that: even m will work because no other arguments
    start with m).
    args(melt.data.frame)
    function (data, id.vars, measure.vars, variable_name = "variable",
    na.rm = !preserve.na, preserve.na = TRUE, ...)

    Bottom line: you need something like

    melt.data.frame(smiths, measure.vars = c("age", "weight", "height"))

    Best,
    Ista

    On Tue, Oct 5, 2010 at 11:36 AM, Dimitri Liakhovitski
    wrote:
    Hellow!

    I am replicating the example givien in "Reshaping Data with the
    reshape Package" (http://www.jstatsoft.org/v21/i12 - see "download"
    link on the right), p. 2-3.

    library(reshape)
    data(smiths)
    str(smiths)

    The text says: "If you specify only one of measured and identifier
    variables, melt assumes that all the other variables are the OTHER
    sort:"
    Hence, the result of the following 5 lines should be identical:

    melt.data.frame(smiths, id = c("subject", "time"), measured = c("age",
    "weight","height"))
    melt.data.frame(smiths, id = c("subject", "time"))
    melt.data.frame(smiths, id = 1:2)
    melt.data.frame(smiths, measured = c("age", "weight", "height"))
    melt.data.frame(smiths) ? ? ? ? ? ? ? ? ? # If you do not specify them
    explicitly, melt will assume that any factor or character variables
    are id variables


    However, only the first 3 lines produce the same result.
    I am especially surprised why line 4 uses "time" as a measured
    variable, while it should be clear to reshape that "time" is NOT a
    measured variable?


    Thank you!
    --
    Dimitri Liakhovitski
    Ninah Consulting
    www.ninah.com

    ______________________________________________
    R-help at r-project.org mailing list
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.


    --
    Ista Zahn
    Graduate student
    University of Rochester
    Department of Clinical and Social Psychology
    http://yourpsyche.org
  • Dimitri Liakhovitski at Oct 5, 2010 at 5:07 pm
    Thank you, Ista!

    you are right - in the paper I was refering to it's "measured" but in
    ?melt it's measure.vars!

    Dimitri
    On Tue, Oct 5, 2010 at 12:17 PM, Ista Zahn wrote:
    Hi Dimitri,
    The argument names may have changed. Notice that

    melt.data.frame(smiths, measured = c("age", "weight", "height"))

    gives a message saying "Using subject as id variables". This is
    because measured variables need to be specified as measure.vars (or an
    abbreviation of that: even m will work because no other arguments
    start with m).
    args(melt.data.frame)
    function (data, id.vars, measure.vars, variable_name = "variable",
    ? ?na.rm = !preserve.na, preserve.na = TRUE, ...)

    Bottom line: you need something like

    melt.data.frame(smiths, measure.vars = c("age", "weight", "height"))

    Best,
    Ista

    On Tue, Oct 5, 2010 at 11:36 AM, Dimitri Liakhovitski
    wrote:
    Hellow!

    I am replicating the example givien in "Reshaping Data with the
    reshape Package" (http://www.jstatsoft.org/v21/i12 - see "download"
    link on the right), p. 2-3.

    library(reshape)
    data(smiths)
    str(smiths)

    The text says: "If you specify only one of measured and identifier
    variables, melt assumes that all the other variables are the OTHER
    sort:"
    Hence, the result of the following 5 lines should be identical:

    melt.data.frame(smiths, id = c("subject", "time"), measured = c("age",
    "weight","height"))
    melt.data.frame(smiths, id = c("subject", "time"))
    melt.data.frame(smiths, id = 1:2)
    melt.data.frame(smiths, measured = c("age", "weight", "height"))
    melt.data.frame(smiths) ? ? ? ? ? ? ? ? ? # If you do not specify them
    explicitly, melt will assume that any factor or character variables
    are id variables


    However, only the first 3 lines produce the same result.
    I am especially surprised why line 4 uses "time" as a measured
    variable, while it should be clear to reshape that "time" is NOT a
    measured variable?


    Thank you!
    --
    Dimitri Liakhovitski
    Ninah Consulting
    www.ninah.com

    ______________________________________________
    R-help at r-project.org mailing list
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.


    --
    Ista Zahn
    Graduate student
    University of Rochester
    Department of Clinical and Social Psychology
    http://yourpsyche.org


    --
    Dimitri Liakhovitski
    Ninah Consulting
    www.ninah.com

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupr-help @
categoriesr
postedOct 5, '10 at 3:36p
activeOct 5, '10 at 5:07p
posts3
users2
websiter-project.org
irc#r

2 users in discussion

Dimitri Liakhovitski: 2 posts Ista Zahn: 1 post

People

Translate

site design / logo © 2022 Grokbase