An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121213/ad240762/attachment.pl>
how to aggregate the dataset
2 messages · Tammy Ma, arun
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.