1
我想要另一個向量,其中每個數值是=它是當前值減去(它在向量中的位置 - 1),例如,如何根據序列中的位置來修改向量元素
說我有
positions <- c(9, 30, 46, 52, 76)
我想
感謝另一矢量,它等於C(9,29,44,49,72)
我想要另一個向量,其中每個數值是=它是當前值減去(它在向量中的位置 - 1),例如,如何根據序列中的位置來修改向量元素
說我有
positions <- c(9, 30, 46, 52, 76)
我想
感謝另一矢量,它等於C(9,29,44,49,72)
x <- c(9, 30, 46, 52, 76)
x - (seq_along(x)-1)
[1] 9 29 44 49 72
answer <- positions - 0:4
0:4
是矢量c(0,1,2,3,4)