I am trying to reshape a data frame, and the task is just different enough from a typical reshape that I can't quite swing it. The table is originally in excel, but I've already imported to R, so I can work with a solution in either software.
I have a data frame donors containing names, values, and months:
NAME AMT MONTH
brett 100 jan
brett 100 mar
brett 100 nov
brett 50 apr
brett 50 jun
jane 75 dec
sam 200 jan
sam 200 feb
sam 200 mar
I need to reshape this data frame so that there is a NAME column, an AMT column, and a column for each month. Each row corresponds to any observation that is unique in both name and amount, and the month columns are binary variables (1 if that donor/amount combo occurred that month, and 0 if not.
So the above example would work out to:
NAME AMT JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
brett 100 1 0 1 0 0 0 0 0 0 0 1 0
brett 50 0 0 0 1 0 1 0 0 0 0 0 0
jane 75 0 0 0 0 0 0 0 0 0 0 0 1
sam 200 1 1 1 0 0 0 0 0 0 0 0 0
if you want to complete my code, create a final column equal to the total number of times that NAME/AMT combo occurred (just equal to the sum of the month columns)... but I can do that myself if you aren't feeling it.
Thank you!