I am working on a simple pilot project comparing the capability of SQL,
SAS and R to perform a rolling mean per the following instructions. I
have completed the SQL and SAS analysis, so now it's R's turn. 

Calculate mean values of x (x=count) for each date in the dataset where
mean = the average count of days [t-9] through day [t-3] for each
date/illness combination.

Dataset aggpilot

     date           illness x
1    2006/01/01    DERM 319
2    2006/01/02    DERM 388
3    2006/01/03    DERM 336
4    2006/01/04    DERM 255
5    2006/01/05    DERM 177
6    2006/01/06    DERM 377
7    2006/01/07    DERM 113
8    2006/01/08    DERM 253
9    2006/01/09    DERM 316
10   2006/01/10    DERM 187
11   2006/01/11    DERM 292
12   2006/01/12    DERM 275
13   2006/01/13    DERM 355
... 3102 total observations

Result of command: str(aggpilot)

'data.frame':   3102 obs. of  3 variables:
  $ date   : Factor w/ 1551 levels "2006/01/01","2006/01/02",..: 1 2 3 4
5 6 7 8 9 10 ...
  $ illness: Factor w/ 2 levels "DERM","FEVER": 1 1 1 1 1 1 1 1 1 1 ...
  $ x      : int  319 388 336 255 177 377 113 253 316 187 ...

The results should look something like this:

DATE    ILLNESS x       MEAN                    NOTES [ROLLING MEAN DATE
RANGE]
1/1/2006        DERM    319     
1/2/2006        DERM    388     
1/3/2006        DERM    336     
1/4/2006        DERM    255     319                     [1/1/2006 -
1/1/2006]
1/5/2006        DERM    177     353.5                   [1/1/2006 -
1/2/2006]
1/6/2006        DERM    377     347.6666667             [1/1/2006 -
1/3/2006]
1/7/2006        DERM    113     324.5                   [1/1/2006 -
1/4/2006]
1/8/2006        DERM    253     295                     [1/1/2006 -
1/5/2006]
1/9/2006        DERM    316     308.6666667             [1/1/2006 -
1/6/2006]
1/10/2006       DERM    187     280.7142857             [1/1/2006 -
1/7/2006]
1/11/2006       DERM    292     271.2857143             [1/2/2006 -
1/8/2006]
1/12/2006       DERM    275     261                     [1/3/2006 -
1/9/2006]
1/13/2006       DERM    355     239.7142857             [1/4/2006 -
1/10/2006]


Ken Hall 
Computer Scientist 
Division of Healthcare Information (DHI) (proposed)
Public Health Surveillance Program Office (proposed)
Office of Surveillance, Epidemiology, & Laboratory Services (OSELS)
(proposed)
Centers for Disease Control & Prevention (CDC)
k...@cdc.gov 
Mobile: 404-993-3311 
Office: 404-498-6839



        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to