2
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)))       

I have tried this code.I get the group by for total & count but not for percent ?

Robin Gertenbach
  • 10,316
  • 3
  • 25
  • 37
R.Mishra
  • 31
  • 1
  • 4
  • @akrun Did you overwrite the code on purpose? – Robin Gertenbach Aug 26 '16 at 10:59
  • @RobinGertenbach Sorry, I didn't get you. Why should I do that on purpose? I didn't do anything except made the code formatted. You can look at the edit history – akrun Aug 26 '16 at 10:59
  • 1
    @akrun You copied in the code from the linked post, checking the revision history the code was very different. – Robin Gertenbach Aug 26 '16 at 11:00
  • @RobinGertenbach My comment to your response got somehow deleted. Yes, when I formatted it, I copied the wrong one. Sorry for that. I am not sure who is deleting a genuine response. It seems like somebody want to show I did it purposefully. – akrun Aug 27 '16 at 04:48

1 Answers1

3

We need to change to Customers$Customer.Value and also for better understanding, use the %>% instead of using nested functions.

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)))       

As the OP didn't show any reproducible example, we also have a doubt of the closing bracket in sum(Customer.Value*100

akrun
  • 874,273
  • 37
  • 540
  • 662