I have a data frame that looks like this :
a | b |
---|---|
7 | -12 |
18 | -22 |
29 | -32 |
40 | -42 |
51 | -52 |
I want to slide from top to bottom with:
sliding window 3 :
7 -22 = -15
7 -32 = -25
18 -42 = -24
29 -52 = -23
40 -52 = -12
from this calculations I want R to report me the minimum which is -25.
for sliding window 5 :
7-32 =-25
7-42 = -35
7 -52 = -45
18 -52 =-34
29-52 =-23
and R to report me -45.
How can I do this in R ?
library(tidyverse)
a = c(7,18,29,40,51)
b = c(-12,-22,-32,-42,-52)
w = tibble(a,b);w