Hi. There are several ways how to do it. You could find them easily using Google. e.g.
https://stackoverflow.com/questions/19200841/consecutive-rolling-sums-in-a-vector-in-r where you find several options. Cheers Petr > -----Original Message----- > From: R-help <r-help-boun...@r-project.org> On Behalf Of Dr Eberhard > Lisse > Sent: Tuesday, August 17, 2021 12:25 PM > To: r-help@r-project.org > Subject: [R] Rolling 7 day incidence > > Hi, > > I am loading the coronavirus dataset everyday which looks something like: > > > as_tibble(coronavirus) %>% > filter(country=="Namibia" & type=="confirmed") %>% > arrange(desc(date)) %>% > print(n=10) > > # A tibble: 573 × 7 > date province country lat long type cases > <date> <chr> <chr> <dbl> <dbl> <chr> <dbl> > 1 2021-08-16 "" Namibia -23.0 18.5 confirmed 76 > 2 2021-08-15 "" Namibia -23.0 18.5 confirmed 242 > 3 2021-08-14 "" Namibia -23.0 18.5 confirmed 130 > 4 2021-08-13 "" Namibia -23.0 18.5 confirmed 280 > 5 2021-08-12 "" Namibia -23.0 18.5 confirmed 214 > 6 2021-08-11 "" Namibia -23.0 18.5 confirmed 96 > 7 2021-08-10 "" Namibia -23.0 18.5 confirmed 304 > 8 2021-08-09 "" Namibia -23.0 18.5 confirmed 160 > 9 2021-08-08 "" Namibia -23.0 18.5 confirmed 229 > 10 2021-08-07 "" Namibia -23.0 18.5 confirmed 319 > # … with 563 more rows > > How do I do a rolling 7 day incidence (ie sum the cases over 7 days) but > rolling, ie from the last day to 7 (or 6?) days before the end of the > dataset, so > I get pairs of date/7-Day-Incidence? > > I know it's probably re-inventing the plot as it were but I can't find R code > to > do that. > > I want to plot it per 100000 but that I can do. > > greetings, el > > > -- > To email me replace 'nospam' with 'el' > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.