How to calculate cumulative sum? [duplicate] August 6, 2022 by Tarik # replace the second column for the cumsum of the initial second column data[, 2] <- cumsum(data[, 2])