Skip to content
Back to formatted view

Raw Message

Message-ID: <f8e6ff050612311058p7b79e274y1f2742a02cbfc6ed@mail.gmail.com>
Date: 2006-12-31T18:58:53Z
From: Hadley Wickham
Subject: tabulate: switching columns and rows
In-Reply-To: <20061231T194404Z_C5AC00020000@xen.net>

> 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