[R] cast in reshape and reshape2
Hadley Wickham
hadley at rice.edu
Sat Dec 24 03:22:18 CET 2011
On Fri, Dec 23, 2011 at 1:58 PM, Kaiyin Zhong <kindlychung at gmail.com> wrote:
>> library(reshape2)
>> x = melt(airquality, id=c('month', 'day'))
>
> With reshape I can cast with multiple functions:
>
>> library(reshape)
>> cast(x, month+variable~., c(mean,sd))
> month variable mean sd
> 1 5 ozone 23.615385 22.224449
> 2 5 solar.r 181.296296 115.075499
> 3 5 wind 11.622581 3.531450
> 4 5 temp 65.548387 6.854870
> 5 6 ozone 29.444444 18.207904
> 6 6 solar.r 190.166667 92.882975
> 7 6 wind 10.266667 3.769234
> 8 6 temp 79.100000 6.598589
> 9 7 ozone 59.115385 31.635837
> 10 7 solar.r 216.483871 80.568344
> 11 7 wind 8.941935 3.035981
> 12 7 temp 83.903226 4.315513
> 13 8 ozone 59.961538 39.681210
> 14 8 solar.r 171.857143 76.834943
> 15 8 wind 8.793548 3.225930
> 16 8 temp 83.967742 6.585256
> 17 9 ozone 31.448276 24.141822
> 18 9 solar.r 167.433333 79.118280
> 19 9 wind 10.180000 3.461254
> 20 9 temp 76.900000 8.355671
>
> Is there a way to do the same job with reshape2?
No, this is something that reshape2 does not support.
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
More information about the R-help
mailing list