In R, I have a couple of tibbles with many rows (4 million or so). I run a loop through one of the tibbles to construct cumulative series based on the other tibble.
for (i in 1:nrow(PortfolioDevt)){
if (PortfolioDevt$Period[i] == 0){
PortfolioDevt$Assets[i] <- 100
} else {
PortfolioDevt$Assets[i] <- PortfolioDevt$Assets[i-1] * (1 + css$Return[i])
}
}
However, I am really disappointed with the speed of this.
Am I making some beginner's mistake here? Is there a much faster way to do this?
PS: There is nothing wrong with the results, which are as expected, except for running time. :(