I have a matrix with three columns: county, date, and number of ED visits. The dates repeat for each county, like this (just an example):
County A 1/1/2012 2
County A 1/2/2012 0
County A 1/3/2012 5
... etc.
County B 1/1/2012 3
County B 1/2/2012 4
... etc.
I would like to collapse this matrix to sum the visits from all counties for each date. So it would look like this:
1/1/2012 5
1/2/2012 4
etc.
I am trying to use the "table()"
function in R but can't seem to get it to operate on visits by date in this manner. When I do "table(dt$date, dt$Visits)"
it gives me a table of frequencies like this:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
2011-01-01 3 1 2 0 1 1 0 2 0 0 0 0 0 0 0 0
2011-01-02 2 3 1 0 0 1 0 0 1 0 2 0 0 0 0 0
2011-01-03 3 1 1 2 1 0 0 0 0 1 0 0 0 0 1 0
Any suggestions? Is there a better function to use, perhaps a "sum" of some sort?
Thanks!