Reputation: 1639
I'm trying to find a simple function in R on how to iteratively sum a vector values and result in another vector.
Suppose I have a vector of [2,3,5,2,6,3]
I need a vector which sums and results as [2,5,10,12,18,21]
Upvotes: 0
Views: 268
Reputation: 63
x <- c(2,3,5,2,6,3)
cumsum(x)
[1] 2 5 10 12 18 21
Here is your function, man.
Upvotes: 1