I have a large dataset containing the names of hospitals, the hospital groups and then the number of presenting patients by month. I'm trying to use dplyr to create a summary that contains the total number of presenting patients each month, aggregated by hospital group. The data frame looks like this:
Hospital | Hospital_group | Jan 03 | Feb 03 | Mar 03 | Apr 03 | .....
---------------------------------------------------------------
Hosp 1   | Group A        |    5   |    5   |    6   |    4   | .....
---------------------------------------------------------------
Hosp 2   | Group A        |    6   |    3   |    8   |    2   | .....
---------------------------------------------------------------
Hosp 3   | Group B        |    5   |    5   |    6   |    4   | .....
---------------------------------------------------------------
Hosp 4   | Group B        |    3   |    7   |    2   |    1   | .....
---------------------------------------------------------------
I'm trying to create a new dataframe that looks like this:
Hospital_group |Jan 03 | Feb 03 | Mar 03 | Apr 03 | .....
----------------------------------------------------------
Group A        |   11  |    8   |    14  |   6    | .....
----------------------------------------------------------
Group B        |   8   |    12  |     8  |   5    | .....
----------------------------------------------------------
I'm trying to use dplyr to summarise the data but am a little stuck (am very new at this as you might have guessed). I've managed to filter out the first column (hospital name) and group_by the hospital group but am not sure how to get a cumulative sum total for each month and year (there is a large number of date columns so I'm hoping there is a quick and easy way to do this).
Sorry about posting such a basic question - any help or advice would be greatly appreciated.
Greg
 
     
    