[R] tabulate: switching columns and rows

hadley wickham h.wickham at gmail.com
Sun Dec 31 19:58:53 CET 2006


> Thanks, Hadley,
>
> My fault: I've not provided the line concerning replicate variable. It is included in ?xtabs:
>
> warpbreaks$replicate <- rep(1:9, len = 54)
>
> It will be great to have an example with these given data. Anyway, I will have a look to reshape at the given site. Thanks a lot!


install.packages("reshape")
library(reshape)

wm <- melt(warpbreaks, m="breaks")
cast(wm, wool ~ tension + replicate)

# Or as a 3d array
cast(wm, wool ~ tension ~ replicate)

# Or aggregate over replicates:
cast(wm, wool ~ tension, mean)
cast(wm, wool ~ tension, length)

Regards,

Hadley



More information about the R-help mailing list