當我嘗試計算百分比時,有兩個數據框出現問題。在第一個數據框中,我累積了一個人進行的不同操作的金額。這些數據幀,第一個是與每個人的信息的原始數據幀:如何計算考慮第一個數據框中的一個變量的百分比是來自另一個數據框中不同值的彙總總和
ID Final.Amount
1 0001 50
2 0002 30
3 0003 90
4 0004 50
我wanto calcule的百分比與每個ID:
z=data.frame(ID=c("0001","0002","0002","0001","0003","0003","0004","0004","0001","0003"),Amount=c(10,20,10,30,50,10,40,10,10,30),Place=c("KFC","Marcys","Ezone","Ezone","Italocafe","Italocafe","KFC","Walmart","KFC","KFC"))
當我聚集我有此之後放置變量,我嘗試了plyr但我沒有得到結果。我想找一個這樣的:
ID Final.Amount Perct.KFC Perct.Macys Perct.Ezonne Perct.Italocafe Percent.Walmart
1 0001 50 40% 0% 60% 0% 0%
2 0002 30 0% 67% 33% 0% 0%
3 0003 90 33% 0% 0% 67% 0%
4 0004 50 80% 0% 0% 0% 20%
我試着用plyr,但我沒有得到正確的結構,我不知道我是否需要sqldf或其他包裝。
(+1)like like ... – Arun 2013-03-14 16:13:07