Calculate average of vector elements adjacent to and excluding the index element. For example, the second element of the result is the average of the first and third elements of the input vector x. Used by smooth_age_5_zigzag_inner(), and possibly useful elsewhere.

avg_adj(x)

Arguments

x

numeric vector

Value

numeric vector the same length as x.

Details

Tails are given a value of NA.

Examples

x <- 1:10 all(avg_adj(x) == x, na.rm = TRUE)
#> [1] TRUE