[R] reshape not using as id vars what it is supposed to be using?
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@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.
Re: [R] reshape not using as id vars what it is supposed to be using?
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 dimitri.liakhovit...@gmail.com 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@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 __ R-help@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.
Re: [R] reshape not using as id vars what it is supposed to be using?
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 iz...@psych.rochester.edu 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 dimitri.liakhovit...@gmail.com 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@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 __ R-help@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.