-2

My DF has two columns One is state names and another one is No of event happened. This Data had more columns and now I want to sum up all the no of events happened by state. how can I do that?

Nirali Khoda
  • 388
  • 5
  • 19

1 Answers1

0

How about using dplyr,

library(dplyr)
DF %>%
  group_by(state) %>%
  summarize(total_event = sum(event))

Here I have supposed your data is in DF data frame and it has columns names state and event.

TheRimalaya
  • 4,232
  • 2
  • 31
  • 37
  • It didn't help me. I got help from below code. aggregate(df$Total, by=list(Category=df$State), FUN=sum) – Nirali Khoda Aug 04 '17 at 09:08
  • That is very fine, it might help you in future when you will have to do more sophisticated summaries and groupings. `data.table` and `dplyr` are very good alternatives. – TheRimalaya Aug 04 '17 at 12:46