I'm having an issue trying to do something that I feel is quite simple.
I have a data set like this, the years span 1998 to 2017, states are states in Brazil, then it lists the amount of fires per month:
year state month number
<int> <fct> <fct> <dbl>
1998 Acre January 0
1998 Acre February 0
1998 Acre March 0
1998 Acre April 0
1998 Acre May 0
1998 Acre June 3
1998 Acre July 37
1998 Acre August 130
1998 Acre September 509
1998 Acre October 44
and I want to change it to wide format so it lists the year and the total count for the year without information about the month and state, so that I can make a graph of the trend over the period. I'm envisioning data like this:
year number
1998 (count)
1999 (count)
2000 (count)
I haven't used R for a little while and am a bit rusty on data manipulation, I've tried a bunch of things like using spread()
and group_by()
together, but I keep getting the error:
Error: Each row of output must be identified by a unique combination of keys.
Any ideas as to how I can go about this? Sorry for the super simple question!
Thanks in advance!