Having trouble getting either tidyr, reshape, or reshape2 to do something I imagine to be simple.
Have data that looks like this:
agecat year Drug total
<1 1999 Amikacin 12
<1 1999 Cefepime 3
<1 1999 Ceftazidime 13
<1 2000 Amikacin 3
<1 2000 Cefepime 6
<1 2000 Ceftazidime 3
<1 2000 Ciprofloxacin 4
1-5 1999 Amikacin 37
1-5 1999 Cefepime 25
1-5 1999 Ceftazidime 38
1-5 1999 Ciprofloxacin 38
1-5 2000 Amikacin 52
1-5 2000 Cefepime 34
1-5 2000 Ceftazidime 45
..but much longer, there are 4 agecats, 14 years (1999-2012), and 10 drugs, each with a unique total. I want to spread 'year' and maintain total, basically to have a wideform 'timeline' of trends in agecat by drug. I.e.
agecat drug 1999 2000
<1 Amikacin 23 3
<1 Cefepime 3 6
I've had great luck with spread in tidyr when there's only two grouping variables, but adding the third seems to throw it all off...I either get a sparse matrix or a names matching error. With melt/dcast, I've tried adding an ID column (1:n rows) but still no go...and I'm having trouble understanding what function to apply when I don't want to change the data, just make it wideform. What am I missing? Thanks!