HI,
You can also also ?reshape()
res<-reshape(base,v.names="r",idvar="p",timevar="q",direction="wide")
res[order(res$p),]
A.K.
- Original Message -
From: CE.KA
To: r-help@r-project.org
Cc:
Sent: Saturday, December 1, 2012 7:37 AM
Subject: [R] How to built a pivot table of value
Hi R
Blast, you're right. I tend to load both at the same time and confused the two.
It should be reshape2
John Kane
Kingston ON Canada
> -Original Message-
> From: b...@xs4all.nl
> Sent: Sat, 1 Dec 2012 15:20:13 +0100
> To: jrkrid...@inbox.com
> Subject: Re: [R] How to
On 01-12-2012, at 14:56, John Kane wrote:
> One way, using the plyr package would be:
>
> library(plyr)
> dcast(base, p ~ q)
>
Shouldn't that be library(reshape2) ?
Berend
> John Kane
> Kingston ON Canada
>
>
>> -Original Message-
>> From: ce.kay...@yahoo.fr
>> Sent: Sat, 1 Dec 20
One way, using the plyr package would be:
library(plyr)
dcast(base, p ~ q)
John Kane
Kingston ON Canada
> -Original Message-
> From: ce.kay...@yahoo.fr
> Sent: Sat, 1 Dec 2012 04:37:02 -0800 (PST)
> To: r-help@r-project.org
> Subject: [R] How to built a pivot table of value
>
> Hi
On 01-12-2012, at 13:37, CE.KA wrote:
> Hi R users
>
> Imagine the table "base":
> p=c("d","d","b","b","a","a")
> q=c("v1","v2","v1","v2","v1","v2")
> r=c(5,2,4,8,9,7)
> base=data.frame(p,q,r)
> base
>
> p q r
> 1 d v1 5
> 2 d v2 2
> 3 b v1 4
> 4 b v2 8
> 5 a v1
Hi,
One way could be
with(base, tapply(r, list(p, q), sum))
HTH,
Jorge.-
On Sat, Dec 1, 2012 at 11:37 PM, CE.KA <> wrote:
> Hi R users
>
> Imagine the table "base":
> p=c("d","d","b","b","a","a")
> q=c("v1","v2","v1","v2","v1","v2")
> r=c(5,2,4,8,9,7)
> base=data.frame(p,q,r)
> base
>
>
6 matches
Mail list logo