I have the following situation:
In a numeric matrix type:
Temp <- matrix(runif(25, 10, 100),nrow=5,ncol=5)
V1 V2 V3 V4 V5
11 34 45 54 55
16 21 45 75 61
88 49 85 21 22
12 13 12 11 10
69 45 75 78 89
How to transform this matrix into a matrix that is the cumulative sum of columns? The result would be as follows
V1 V2 V3 V4 V5
11 45 90 144 199
16 37 82 157 218
88 137 222 243 265
12 25 37 48 58
69 114 189 267 356
I have achieved the goal using a for loop, but I believe there should be a more efficient way to do it since I am working with a 2580-matrix matrix for 253 columns and it takes a while to generate the result
Temp <- matrix(runif(25, 10, 100),nrow=5,ncol=5)
Temp <- round(Temp,0)
sum_matrix <- matrix(0,nrow=nrow(Temp),ncol=ncol(Temp))
sum_matrix[,1] <- Temp[,1]
for (n in 2:nrow(Temp)) {
sum_matrix[,n] <- sum_matrix[,n-1] + Temp[,n]
}