如何根据序列中的位置修改矢量元素

luk*_*123 1 r

我想要另一个向量,其中每个数值= =它的当前值减去(它在向量中的位置 - 1),例如

说我有

positions <- c(9,  30,  46,  52,  76)
Run Code Online (Sandbox Code Playgroud)

我想要另一个等于c的向量(9,29,44,49,72)

谢谢

the*_*ail 6

x  <- c(9,  30,  46,  52,  76)
x - (seq_along(x)-1)
[1]  9 29 44 49 72
Run Code Online (Sandbox Code Playgroud)