Expand numeric vector elements with constant (natural number)

Viewed 95

Given a vector v <- c(1, 10, 22) and a constant natural number say c <- 3 how can I expand v with integers in a window of size c. So the vector would become w (i.e. 1 is expanded three integers to each side, the integers -2, -1, 0, 1, 2, 3, 4) :

> w
 [1] -2 -1  0  1  2  3  4  7  8  9 10 11 12 13 19 20 21 22 23 24 25
4 Answers
Related