Re: [R] tabulate: switching columns and rows

From: hadley wickham <>
Date: Sun 31 Dec 2006 - 18:58:53 GMT

> 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!


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)


Hadley mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon Jan 01 06:02:53 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 31 Dec 2006 - 21:30:24 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.