I know this question has been asked before, but I don't quite understand.
I have a dataset that looks like this:
Precinct Crime 2000 2001 2002 2003
1 Murder 3 1 2 2
1 Rape 12 5 10 11
1 Burglary 252 188 297 403
2 Murder 4 2 1 0
with the values of each crime listed under the year.
I'm trying to rearrange it into simpler sets that look like this:
Precinct Crime Year Value
1 Murder 2000 3
1 Rape 2000 12
How do I go about doing that? I know I should be using tidyr's gather
, but extrapolating solutions for multiple keys isn't working for me.
gather(df1, Year, Value, 3:ncol(df1))
– Grudge