The function rollapply
in package zoo
should do the trick:
library(zoo)
values = c(29.66, 29.59, 30.05, 29.59, 29.59, 30.05, 29.59, 29.92, 30.26, 30.18, 30.47)
rollmax(values, k=3)
# or
rollapply(values, 3, max)
# [1] 30.05 30.05 30.05 30.05 30.05 30.05 30.26 30.26 30.47
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…