Re: [R] Break up a data frame
"Ravi S. Shankar" <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Hi R users, > > > > I have a dataframe in the below format > > xyz 01/03/200715.25USD > > xyz 01/04/200715.32USD > > xyz 01/02/200823.22USD > > abc 01/03/200745.2 EUR > > abc 01/04/200745.00EUR > > abc 01/02/200868.33EUR > > > > I want to change the above data into the below format > > > > > > xyz 01/03/200715.25USD > abc > 01/03/200745.2 EUR > > xyz 01/04/200715.32USD > abc > 01/04/200745.00EUR > > xyz 01/02/200823.22USD > abc > 01/02/200868.33EUR > > Seeing what appeared to be wordwrap, I interpreted your request as asking for display of "xyz" rows adjacent to "abc" rows. If that is the case, then this seems to work for the toy example: > xz <- read.table("clipboard") > xz V1 V2V3 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 > cbind(xz[xz$V1=="xyz",],xz[xz$V1=="abc",]) V1 V2V3 V4 V1 V2V3 V4 1 xyz 01/03/2007 15.25 USD abc 01/03/2007 45.20 EUR 2 xyz 01/04/2007 15.32 USD abc 01/04/2007 45.00 EUR 3 xyz 01/02/2008 23.22 USD abc 01/02/2008 68.33 EUR If it was instead a request for USD next to EUR, then the needed modifications should be obvious. -- David Winsemius __ R-help@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.
Re: [R] Break up a data frame
Or perhaps: xtabs(V3 ~ V2 + V4, data=x) On 20/03/2008, Ravi S. Shankar <[EMAIL PROTECTED]> wrote: > Hi R users, > > > > I have a dataframe in the below format > > xyz 01/03/200715.25USD > > xyz 01/04/200715.32USD > > xyz 01/02/200823.22USD > > abc 01/03/200745.2 EUR > > abc 01/04/200745.00EUR > > abc 01/02/200868.33EUR > > > > I want to change the above data into the below format > > > > > > xyz 01/03/200715.25USD abc > 01/03/200745.2 EUR > > xyz 01/04/200715.32USD abc > 01/04/200745.00EUR > > xyz 01/02/200823.22USD abc > 01/02/200868.33EUR > > > > Any help would be welcome > > > > Thank you > > > > Ravi > > > > > > This e-mail may contain confidential and/or privileged i...{{dropped:13}} > > __ > R-help@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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O __ R-help@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.
Re: [R] Break up a data frame
Is this close to what you want? > x <- read.table('clipboard') > x V1 V2V3 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 V2V3 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 <[EMAIL PROTECTED]> wrote: > Hi R users, > > > > I have a dataframe in the below format > >xyz 01/03/200715.25USD > >xyz 01/04/200715.32USD > >xyz 01/02/200823.22USD > >abc 01/03/200745.2 EUR > >abc 01/04/200745.00EUR > >abc 01/02/200868.33EUR > > > > I want to change the above data into the below format > > > > > >xyz 01/03/200715.25USD abc > 01/03/200745.2 EUR > >xyz 01/04/200715.32USD abc > 01/04/200745.00EUR > >xyz 01/02/200823.22USD abc > 01/02/200868.33EUR > > > > Any help would be welcome > > > > Thank you > > > > Ravi > > > > > > This e-mail may contain confidential and/or privileged i...{{dropped:13}} > > __ > R-help@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? __ R-help@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.
[R] Break up a data frame
Hi R users, I have a dataframe in the below format xyz 01/03/200715.25USD xyz 01/04/200715.32USD xyz 01/02/200823.22USD abc 01/03/200745.2 EUR abc 01/04/200745.00EUR abc 01/02/200868.33EUR I want to change the above data into the below format xyz 01/03/200715.25USD abc 01/03/200745.2 EUR xyz 01/04/200715.32USD abc 01/04/200745.00EUR xyz 01/02/200823.22USD abc 01/02/200868.33EUR Any help would be welcome Thank you Ravi This e-mail may contain confidential and/or privileged i...{{dropped:13}} __ R-help@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.