PROTECTED] on behalf of ppaarrkk
Sent: Sat 26/04/2008 7:54 AM
To: r-help@r-project.org
Subject: [R] Equivalent of Excel pivot tables in R
Can somebody tell me how to do the equivalent of a pivot table in R ?
For example, if I have :
var1var2 var3
a x10
b y20
a
Hi,
I forgot the first part (I'm sorry):
table(var1,var2)
var2
var1 x y z
a 1 0 2
b 0 1 2
HTH,
Jorge
On Fri, Apr 25, 2008 at 7:25 PM, Jorge Ivan Velez <[EMAIL PROTECTED]>
wrote:
>
> Hi,
>
> Try this:
>
> x="var1var2 var3
> a x10
> b y20
> a
Try:
with(x, tapply(var3, list(var1, var2), length))
with(x, tapply(var3, list(var1, var2), sum))
Or with xtabs
xtabs(as.logical(var3) ~ var1 + var2, data = x)
xtabs(var3 ~ var1 + var2, data = x)
On 4/25/08, ppaarrkk <[EMAIL PROTECTED]> wrote:
>
>
> Can somebody tell me how to do the equiv
See Hadley's reshape package http://had.co.nz/reshape/
and on CRAN.
On Fri, Apr 25, 2008 at 2:54 PM, ppaarrkk <[EMAIL PROTECTED]> wrote:
>
> Can somebody tell me how to do the equivalent of a pivot table in R ?
>
>
> For example, if I have :
>
> var1var2 var3
> a x10
> b
Hi,
Try this:
x="var1var2 var3
a x10
b y20
a z10
b z20
a z10
b z20"
yourdata=read.table(textConnection(x),header=TRUE)
attach(yourdata)
res=tapply(var3,yourdata[,-3],sum) # With tapply!
res[is
Can somebody tell me how to do the equivalent of a pivot table in R ?
For example, if I have :
var1var2 var3
a x10
b y20
a z10
b z20
a z10
b z20
I could have :
x y z
a
6 matches
Mail list logo