Description Usage Arguments Value Author(s) References Examples
Reshapes double and tripple wide data.table
s to long
data.table
s
1 |
data |
The input |
id.vars |
ID variables |
new.names |
The new names for the resulting columns |
A long data.table
Ananda Mahto
http://stackoverflow.com/a/10170630/1270695
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | triplewide <- structure(list(ID = 1:4,
w1d1t1 = c(4L, 3L, 2L, 2L),
w1d1t2 = c(5L, 4L, 3L, 3L),
w1d2t1 = c(6L, 5L, 5L, 4L),
w1d2t2 = c(5L, 4L, 5L, 2L),
w2d1t1 = c(6L, 5L, 4L, 3L),
w2d1t2 = c(5L, 4L, 5L, 5L),
w2d2t1 = c(6L, 3L, 6L, 3L),
w2d2t2 = c(7L, 4L, 3L, 2L)),
.Names = c("ID", "w1d1t1", "w1d1t2",
"w1d2t1", "w1d2t2", "w2d1t1", "w2d1t2",
"w2d2t1", "w2d2t2"),
class = "data.frame",
row.names = c(NA, -4L))
triplewide
triplewide.long <- melt_wide(triplewide, id.vars="ID",
new.names=c("week", "day", "trial"))
triplewide.long
data.table::dcast(triplewide.long, ID + week + day ~ trial)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.