I'm used to doing meltit castall the time, and this time I'm looking for a neat single-line font.
require(reshape)
m <- melt(mtcars, id.vars = c("cyl", "am"), measure.vars = "hp")
cast(m, cyl + am ~ ., each(min, mean, sd, max))
cyl am min mean sd max
1 4 0 62 84.66667 19.65536 97
2 4 1 52 81.87500 22.65542 113
3 6 0 105 115.25000 9.17878 123
4 6 1 110 131.66667 37.52777 175
5 8 0 150 194.16667 33.35984 245
6 8 1 264 299.50000 50.20458 335
Is this possible with ddplyor smth? I desperately need one liner. I tried:
ddply(mtcars, cyl + am ~ hp, each(min, max))
cyl am hp min max
1 4 0 62 0 146.7
2 4 0 95 0 140.8
3 4 0 97 0 120.1
4 4 1 52 1 75.7
5 4 1 65 1 71.1
6 4 1 66 1 79.0
7 4 1 91 0 120.3
8 4 1 93 1 108.0
9 4 1 109 1 121.0
10 4 1 113 1 113.0
11 6 0 105 0 225.0
12 6 0 110 0 258.0
13 6 0 123 0 167.6
14 6 1 110 0 160.0
15 6 1 175 0 175.0
16 8 0 150 0 318.0
17 8 0 175 0 400.0
18 8 0 180 0 275.8
19 8 0 205 0 472.0
20 8 0 215 0 460.0
21 8 0 230 0 440.0
22 8 0 245 0 360.0
23 8 1 264 0 351.0
24 8 1 335 0 335.0
Of course, this works, but without summing up hpon cyland am. This bit is a bit since I used plyrand reshape, therefore, I kind of lost my muscles ... so ... sorry-moi pour une question triviale ... = /
aL3xa source
share