Petr, thank you very much, this pointed me in the right direction (to refine my Google search :-)-O):
library(tidyverse) library(coronavirus) library(zoo) as_tibble(coronavirus) %>% filter(country=='Namibia' & type=="confirmed") %>% mutate(rollsum = rollapplyr(cases, 7, sum, partial=TRUE)) %>% arrange(desc(date)) %>% mutate(R7=rollsum / 25.4 ) %>% select(date,R7) gives me something like # A tibble: 573 × 2 date R7 <date> <dbl> 1 2021-08-16 52.8 2 2021-08-15 56.1 3 2021-08-14 55.6 4 2021-08-13 63.1 5 2021-08-12 62.8 6 2021-08-11 63.7 7 2021-08-10 67.3 8 2021-08-09 69.3 9 2021-08-08 69.2 10 2021-08-07 74.5 # … with 563 more rows which seems to be correct :-)-O so I can now play with ggplot2 over the weekend :-)-O greetings, el On 17/08/2021 12:46, PIKAL Petr wrote:
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
[...] -- 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.