Message-ID: <644e1f320803200245q529abb59h1139678094df3f1f@mail.gmail.com>
Date: 2008-03-20T09:45:58Z
From: jim holtman
Subject: Break up a data frame
In-Reply-To: <A36876D3F8A5734FA84A4338135E7CC3033BE60E@BAN-MAILSRV03.Amba.com>
Is this close to what you want?
> x <- read.table('clipboard')
> x
V1 V2 V3 V4
1 xyz 01/03/2007 15.25 USD
2 xyz 01/04/2007 15.32 USD
3 xyz 01/02/2008 23.22 USD
4 abc 01/03/2007 45.20 EUR
5 abc 01/04/2007 45.00 EUR
6 abc 01/02/2008 68.33 EUR
> x.m <- melt(x)
Using V1, V2, V4 as id variables
> x
V1 V2 V3 V4
1 xyz 01/03/2007 15.25 USD
2 xyz 01/04/2007 15.32 USD
3 xyz 01/02/2008 23.22 USD
4 abc 01/03/2007 45.20 EUR
5 abc 01/04/2007 45.00 EUR
6 abc 01/02/2008 68.33 EUR
> cast(x.m, V2~V4)
V2 EUR USD
1 01/02/2008 68.33 23.22
2 01/03/2007 45.20 15.25
3 01/04/2007 45.00 15.32
>
On Thu, Mar 20, 2008 at 1:22 AM, Ravi S. Shankar <ravis at ambaresearch.com> wrote:
> Hi R users,
>
>
>
> I have a dataframe in the below format
>
> xyz 01/03/2007 15.25 USD
>
> xyz 01/04/2007 15.32 USD
>
> xyz 01/02/2008 23.22 USD
>
> abc 01/03/2007 45.2 EUR
>
> abc 01/04/2007 45.00 EUR
>
> abc 01/02/2008 68.33 EUR
>
>
>
> I want to change the above data into the below format
>
>
>
>
>
> xyz 01/03/2007 15.25 USD abc
> 01/03/2007 45.2 EUR
>
> xyz 01/04/2007 15.32 USD abc
> 01/04/2007 45.00 EUR
>
> xyz 01/02/2008 23.22 USD abc
> 01/02/2008 68.33 EUR
>
>
>
> Any help would be welcome
>
>
>
> Thank you
>
>
>
> Ravi
>
>
>
>
>
> This e-mail may contain confidential and/or privileged i...{{dropped:13}}
>
> ______________________________________________
> R-help at r-project.org 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?