0

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
.
.
.
zx8754
  • 52,746
  • 12
  • 114
  • 209
S31
  • 904
  • 2
  • 9
  • 21

1 Answers1

2

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

data

v1 <- c(6, 14, 22, 30, 38)
akrun
  • 874,273
  • 37
  • 540
  • 662
  • 1
    As this answer original and provides **new solution** to the linked post, I think it is better if you delete this one, and post it to the linked post? – zx8754 Jun 19 '17 at 06:21