I have a large-ish random matrix (either 500 x 100,000 or 500 by 10,000) and I want to apply cumprod to every column. On the 500 x 10,000 my code runs in 13 seconds. On the 500 x 100,000 it runs in 32 minutes. Is there a more efficient or better scaling way than the below to do this within the tidyverse?
library(tidyverse)
library(mc2d)
n.rows = 500 #Number of times
n.cols = 100000 #Number of samples
outcomes = as_tibble(matrix(1 + ifelse(rbern(n.rows * n.cols, .5), .5, -.4),
nrow = n.rows)) %>%
modify(cumprod)