HI, Sorry for messing up.. I want to transform the following dataset: product min_price max_price mean_price country price_band 11 34 50 40 VN 0-300 22 10 30 15 VN 0-300 Into: product VN price_band 11 40 0-300 [34,50] 22 15 0-300 [10,30] How can I do this in r? I have large dataset like this. I want to transform all into that one. Thanks a lot. Kind regards, Tammy [[alternative HTML version deleted]]
Really sorry for messing up. I want to transform:> product min_price max_price mean_price country price_band > 11 34 50 40 VN 0-300 > 22 10 30 15 VN 0-300into> Into: > > product VN price_band > 11 40 0-300 > [34,50] > 22 15 0-300 > [10,30]How Can I do this in r? Kind regards, Tammy From: metal_licaling@live.com To: metal_licaling@live.com Subject: RE: [R] how to aggregate the dataset Date: Thu, 13 Dec 2012 14:22:54 +0300 HI, I want it looks like this:> Into: > > product VN price_band > 11 40 0-300 > [34,50] > 22 15 0-300 > [10,30] >> From: metal_licaling@live.com > To: r-help@r-project.org > Date: Thu, 13 Dec 2012 13:42:35 +0300 > Subject: [R] how to aggregate the dataset > > > HI, > > > > Sorry for messing up.. > > I want to transform the following dataset: > > product min_price max_price mean_price country price_band > 11 34 50 40 VN 0-300 > 22 10 30 15 VN 0-300 > > > Into: > > product VN price_band > 11 40 0-300 > [34,50] > 22 15 0-300 > [10,30] > > > How can I do this in r? I have large dataset like this. I want to transform all into that one. Thanks a lot. > > > Kind regards, > Tammy > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.[[alternative HTML version deleted]]
Hello, maybe something like this? range <- with(dat, paste0("[", min_price, ",", max_price, "]")) dat2 <- with(dat, data.frame(product = product, VN = mean_price, range = range, price_band = price_band)) Unless it's a printing problem and you really want the range below VN. Hope this helps, Rui Barradas Em 13-12-2012 11:24, Tammy Ma escreveu:> Really sorry for messing up. > > I want to transform: > >> product min_price max_price mean_price country price_band >> 11 34 50 40 VN 0-300 >> 22 10 30 15 VN 0-300 > > into > >> Into: >> >> product VN price_band >> 11 40 0-300 >> [34,50] >> 22 15 0-300 >> [10,30] > > How Can I do this in r? > > > Kind regards, > Tammy > > > > > From: metal_licaling at live.com > To: metal_licaling at live.com > Subject: RE: [R] how to aggregate the dataset > Date: Thu, 13 Dec 2012 14:22:54 +0300 > > > > > > HI, > > > I want it looks like this: > >> Into: >> >> product VN price_band >> 11 40 0-300 >> [34,50] >> 22 15 0-300 >> [10,30] >> >> From: metal_licaling at live.com >> To: r-help at r-project.org >> Date: Thu, 13 Dec 2012 13:42:35 +0300 >> Subject: [R] how to aggregate the dataset >> >> >> HI, >> >> >> >> Sorry for messing up.. >> >> I want to transform the following dataset: >> >> product min_price max_price mean_price country price_band >> 11 34 50 40 VN 0-300 >> 22 10 30 15 VN 0-300 >> >> >> Into: >> >> product VN price_band >> 11 40 0-300 >> [34,50] >> 22 15 0-300 >> [10,30] >> >> >> How can I do this in r? I have large dataset like this. I want to transform all into that one. Thanks a lot. >> >> >> Kind regards, >> Tammy >> >> >> >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> 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. > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
Hi, You could try this: dat3<-read.table(text=" product min_price? max_price mean_price country? price_band 11????????? 34????????? 50????????????? 40??????????? VN??????? 0-300 22????????? 10????????? 30????????????? 15??????????? VN??????? 0-300 ",sep="",header=TRUE,stringsAsFactors=FALSE) library(reshape2) SubsetPrice<-dat3[grep("price",names(dat3))] dat3$newPrice<-paste(SubsetPrice[,3],paste("[",SubsetPrice[,1],",",SubsetPrice[,2],"]",sep=""),sep=" ") ?dcast(dat3,product+price_band~country,value.var="newPrice") #? product price_band???????? VN #1????? 11????? 0-300 40 [34,50] #2????? 22????? 0-300 15 [10,30] A.K. ----- Original Message ----- From: Tammy Ma <metal_licaling at live.com> To: "r-help at r-project.org" <r-help at r-project.org> Cc: Sent: Thursday, December 13, 2012 5:42 AM Subject: [R] how to aggregate the dataset HI, Sorry for messing up.. I want to transform the following dataset: product min_price? max_price mean_price country? price_band 11? ? ? ? ? 34? ? ? ? ? 50? ? ? ? ? ? ? 40? ? ? ? ? ? VN? ? ? ? 0-300 22? ? ? ? ? 10? ? ? ? ? 30? ? ? ? ? ? ? 15? ? ? ? ? ? VN? ? ? ? 0-300 Into: product? VN? ? ? ? ? price_band ? 11? ? ? ? 40? ? ? ? ? ? 0-300 ? ? ? ? ? ? [34,50] ? 22? ? ? ? 15? ? ? ? ? ? 0-300 ? ? ? ? ? ? [10,30] How can I do this in r? I have large dataset like this. I want to transform all into that one. Thanks a lot. Kind regards, Tammy ??? ??? ??? ? ??? ??? ? ??? [[alternative HTML version deleted]] ______________________________________________ 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.