简体   繁体   English

seq() function 递增步长

[英]seq() function with increasing increment steps

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.我想生成一个值从 13 到 79 的向量。元素之间的距离应该是值本身的索引。 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?因此 output 将是 13、14、16、19、23、28、34、41、49、58、68、79 我可以使用 seq() 13, 14, 16, 19, 23, 28, 34, 41, 49, 58, 68, 79完成此操作吗? Is there a way to increase the by argument with each step?有没有办法增加每一步by参数?

With accumulate :随着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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM