Say I want to create a vector with 26 values with my starting value being 6. And I want to increase by the previous value plus some arbitrary value (say 8), i.e
6
14 (6+8)
22 (14+8)
30
38
.
.
.
Say I want to create a vector with 26 values with my starting value being 6. And I want to increase by the previous value plus some arbitrary value (say 8), i.e
6
14 (6+8)
22 (14+8)
30
38
.
.
.
We can get the diff
and add
c(v1[1], v1[-length(v1)] + diff(v1))
#[1] 6 14 22 30 38
The above is general one that checks the next value to get the output. But, if we are interested only in a fixed increment, use rep
6 + rep(0:4)*8
#[1] 6 14 22 30 38
v1 <- c(6, 14, 22, 30, 38)