我有这个数据集:
City <- c("New York", "New York", "New York", "New York", "New York",
"Dallas", "Dallas","Dallas","Dallas","Dallas")
Income <- c("1","2","3","4","5","1","2","3","4","5")
Amount <- c(0, 13291.23678, 0,0,0,0, 65666.2885,106896.3682,69949.63342,35549.94405)
DF <- data.frame(City, Income, Amount)
我想计算每个城市的“金额”百分比。我的预期结果是:
City Income Amount Amount_Percentage
New York 1 0.00 0.00%
New York 2 13291.24 100.00%
New York 3 0.00 0.00%
New York 4 0.00 0.00%
New York 5 0.00 0.00%
Dallas 1 0.00 0.00%
Dallas 2 65666.29 23,62%
Dallas 3 106896.37 38,44%
Dallas 4 69949.63 25,16%
Dallas 5 35549.94 12,78%
非常感谢您的帮助。
问候!