Generate a sequence which is an increasing part of

2019-07-11 11:14发布

First of all, sorry for the title. i tried to find an appropriate title.
My "problem" is that I have a vector, say 1-5 from which I would like to make a new vector. Which goes
1, 1,2 , 1,2,3, 1,2,3,4, 1,2,3,4,5

So for each round in includes one new number from the baseline vector until it reaches the end. I have a feeling it should be possible with seq...

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-11 11:44

See ?sequence (from the manpage):

For each element of nvec the sequence seq_len(nvec[i]) is created. These are concatenated and the result returned.

example:

sequence(1:5)
[1] 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
查看更多
登录 后发表回答