Mixalis Mixalis - 7 months ago 44
R Question

Sum data.table and get values before each sum

I'm posting this question because I don't how to phrase it in Google :/

I have a data.table of integers

421 399 350

and I just want to add them but replace each position with the sum at that point.

So pos1 would be 421, pos2=421+399, pos3=421+399+350, etc...

my final output should look like this:

421 820 1170

Can you tell me besides answering the question how I can phrase this in english?


Use cumsum(). It does the cumulative sum.