Adding numbers within a vector in r

后端 未结 1 1266
执笔经年
执笔经年 2021-01-25 00:26

I have a vector

v<-c(1,2,3)

I need add the numbers in the vector in the following fashion

1,1+2,1+2+3

prod

相关标签:
1条回答
  • 2021-01-25 01:03

    Use the cumulative sum function:

    cumsum(v)
    #[1] 1 3 6
    
    0 讨论(0)
提交回复
热议问题