reshape package
Purpose
To understand reshape package and try to explore ways to use it in my work.
> library(reshape) > data(smiths) > melt(smiths, id = c("subject", "time"), measured = c("age", "weight", + "height")) subject time variable value 1 John Smith 1 age 33.00 2 Mary Smith 1 age NA 3 John Smith 1 weight 90.00 4 Mary Smith 1 weight NA 5 John Smith 1 height 1.87 6 Mary Smith 1 height 1.54 > melt(smiths, id = c("subject", "time")) subject time variable value 1 John Smith 1 age 33.00 2 Mary Smith 1 age NA 3 John Smith 1 weight 90.00 4 Mary Smith 1 weight NA 5 John Smith 1 height 1.87 6 Mary Smith 1 height 1.54 > melt(smiths, id = 1:2) subject time variable value 1 John Smith 1 age 33.00 2 Mary Smith 1 age NA 3 John Smith 1 weight 90.00 4 Mary Smith 1 weight NA 5 John Smith 1 height 1.87 6 Mary Smith 1 height 1.54 > melt(smiths) subject variable value 1 John Smith time 1.00 2 Mary Smith time 1.00 3 John Smith age 33.00 4 Mary Smith age NA 5 John Smith weight 90.00 6 Mary Smith weight NA 7 John Smith height 1.87 8 Mary Smith height 1.54 > trial <- data.frame(id = factor(1:4), A1 = c(1, 2, 1, 2), A2 = c(2, + +1, 2, 1), B1 = c(3, 3, 3, 3)) > (trialm <- melt(trial)) id variable value 1 1 A1 1 2 2 A1 2 3 3 A1 1 4 4 A1 2 5 1 A2 2 6 2 A2 1 7 3 A2 2 8 4 A2 1 9 1 B1 3 10 2 B1 3 11 3 B1 3 12 4 B1 3 |
I dont think I will be using this very often. I mean if and when the need arises, I will work on it.
So, that’s it for now as far as reshape package is concerned