0

I feel like this questions should have been answered before, but I fail to find the answer. I want to do a very simple operation in R with a data frame: For each row in ascending order, I want to sum up all the values above (i.e. make a total up to this observation). However, using lag(), I fail to do this. Any suggestions?

moritz
  • 3
  • 3

1 Answers1

0

As Andrew Gustar mentions, e.g.,

cars <- mtcars
cumcyl <- cumsum(cars$cyl)
cars <- cbind(cars, cumcyl)
SteveM
  • 2,226
  • 3
  • 12
  • 16