Reorganizing Data Frame

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Reorganizing Data Frame

chris99
Hi I need some help trying to restructure a data frame:

I have:
food    transaction     quantity
pizza         BUY              5
pizza         SELL              3
apple         BUY              2
orange       SELL              1
pizza         BUY               2


And the data frame I want to make is:

food        BUY          SELL
pizza         7             3
apple         2             0
orange       0             1



I can't figure out the commands to use. Can anyone help?
Reply | Threaded
Open this post in threaded view
|

Re: Reorganizing Data Frame

Henrique Dallazuanna
Try this:

xtabs(quantity ~ food + transaction, DF)

On Tue, Jan 18, 2011 at 5:50 PM, chris99 <[hidden email]> wrote:

>
> Hi I need some help trying to restructure a data frame:
>
> I have:
> food    transaction     quantity
> pizza         BUY              5
> pizza         SELL              3
> apple         BUY              2
> orange       SELL              1
> pizza         BUY               2
>
>
> And the data frame I want to make is:
>
> food        BUY          SELL
> pizza         7             3
> apple         2             0
> orange       0             1
>
>
>
> I can't figure out the commands to use. Can anyone help?
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Reorganizing-Data-Frame-tp3223863p3223863.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>


--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.