[R] Transpose a dataset

Eduardo Leoni leoniedu at msu.edu
Tue Aug 18 22:38:05 CEST 2009


## if x is a matrix this should work
library(reshape)
x <- structure(c(36.41099, 73.60079, 171.94, 67.48221, 131.917, 85.17079,
0.4015699, 9.4656186, 9.201167, 11.7657645, 14.4986667, 17.3150434,
35.1, 50, 153.5, 40, 97, 57.3, 36.22222, 67, 166.5, 60, 122,
70.9, 36.5, 73, 173, 68, 132, 83.1, 36.66667, 80, 176.25, 75,
140, 100, 37.1, 95, 190, 97, 185, 122.5, 89, 253, 20, 253, 253,
89), .Dim = c(6L, 8L), .Dimnames = list(c("BODY_TEMPERATURE",
"DIASTOLIC_BLOOD_PRESSURE", "HEIGHT", "PULSE_RATE", "SYSTOLIC_BLOOD_PRESSURE",
"WEIGHT"), c("mean", "sd", "X0.", "X25.", "X50.", "X75.", "X100.",
"n")))

melt(x)

## if it is a data.frame, read the documentation for the reshape package.




More information about the R-help mailing list