DDD <- summarise(
group_by(Customers, Last_region, Last_state, Last_city),
Count = length(Last_city),
Total = sum(Customer.Value, na.rm = TRUE),
Percent = sum(Customer.Value * 100 / sum(Customer.Value, na.rm = TRUE)))
我已经尝试过这个代码。我得到的总数为&amp;数不是百分比吗?
答案 0 :(得分:3)
我们需要更改为Customers$Customer.Value
并且为了更好地理解,请使用%>%
而不是使用嵌套函数。
Customers %>%
group_by(Last_region, Last_state, Last_city) %>%
summarise(Count = length(Last_city),
Total = sum(Customer.Value, na.rm = TRUE),
Percent = sum(Customer.Value * 100 /
sum(Customers$Customer.Value, na.rm = TRUE)))
由于OP没有显示任何可重现的例子,我们也对sum(Customer.Value*100