[R] reshape not using as id vars what it is supposed to be using?
Dimitri Liakhovitski
dimitri.liakhovitski at gmail.com
Tue Oct 5 17:36:25 CEST 2010
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
More information about the R-help
mailing list