Re: [R] tabulate: switching columns and rows

From: hadley wickham <h.wickham_at_gmail.com>
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!

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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.