Home > other >  seq() function with increasing increment steps
seq() function with increasing increment steps

Time:01-24

I want to generate a vector with the values from 13 to 79. The distance between the elements should be the index of the value itself. So that the output would be 13, 14, 16, 19, 23, 28, 34, 41, 49, 58, 68, 79 Can i accomplish this with the seq() function? Is there a way to increase the by argument with each step?

CodePudding user response:

With accumulate:

Reduce(` `, 1:11, init = 13, accumulate = TRUE)
#[1] 13 14 16 19 23 28 34 41 49 58 68 79

purrr::accumulate(1:11, .init = 13, ` `)
#[1] 13 14 16 19 23 28 34 41 49 58 68 79
  • Related