0

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?

Mixalis
  • 532
  • 5
  • 17
  • if you meant indeed data.table it would be good to provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). What you have shown here are vectors, not data.tables. – Henk Nov 11 '16 at 13:30
  • 1
    Cumulative Sum is the terminology – Sotos Nov 11 '16 at 13:31

1 Answers1

1

Use cumsum(). It does the cumulative sum.

Morgan Ball
  • 760
  • 9
  • 23