根据 R 中的间隔向量生成不规则的数字序列

Generate a irregular sequence of numbers based on a vector of intervals in R

我想通过指定不同间隔的向量创建一个从 -100 到 100 的数字序列。

start<- -100
end <- 100
intervals <- c(10,5,100,4)

output:
-100, -90, -85, 15, 19, 100
c(start + cumsum(c(0, intervals)), end)
# [1] -100  -90  -85   15   19  100

那么"end"就被加在最后了。你可以用它做其他事情,但你必须决定如果你的间隔超过它会发生什么。

另请注意您提出的要求,

I want the length of my sequence to be same length as the interval vector.

与您想要的输出相矛盾。如果你想要不同的行为,你需要更精确。