[R] rollmean help (or similar function)

stephen sefick ssefick at gmail.com
Fri Aug 20 22:13:04 CEST 2010


I don't know if this is what you are after, but have a look at:
rollmean in the zoo package
hth

Stephen


On Fri, Aug 20, 2010 at 2:47 PM, Hall, Ken (CDC/OSELS/NCPHI)
<kha6 at cdc.gov> wrote:
> 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)
> kha6 at cdc.gov
> Mobile: 404-993-3311
> Office: 404-498-6839
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>



-- 
Stephen Sefick
____________________________________
| Auburn University                                   |
| Department of Biological Sciences           |
| 331 Funchess Hall                                  |
| Auburn, Alabama                                   |
| 36849                                                    |
|___________________________________|
| sas0025 at auburn.edu                             |
| http://www.auburn.edu/~sas0025             |
|___________________________________|

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

                                -K. Mullis



More information about the R-help mailing list