I have a list that contains 1000 simulations, each has a sample of dimension 1 x 100:
library(purrr)
simulations <- rerun(1000, rbinom(100, 100, 0.8)) %>% set_names(paste0("sim", 1:1000))
I have another list of numbers of length 500 - or 500 steps:
# Each entry is a step from 1 to 500
foo <- rnorm(500, 200,75) %>% set_names(paste0("step", 1:500))
For each vector in simulations I want multiply it by foo. If we take the first sample vector from simulations we get:
values <- simulations$sim1 %*% t(foo)
Where values is of dimension 100 x 500. I'd like to generate a data structure that is flattened along the three dimensions sim, step and values:
| sim | step | values |
|---|---|---|
| 1 | step1 | v1 |
| .. | .. | .. |
| 1 | step500 | v500 |
| 1 | .. | .. |
| 1 | step1 | v501 |
| 1 | .. | .. |
| 1 | step500 | v1000 |
| 1 | .. | .. |
| 1 | step1 | v50000 |
| 2 | step1 | v1 |
| .. | .. | .. |
| .. | .. | .. |
| 1000 | step500 | v50000 |
So ultimately I should end up with a data structure that has 1000 x 500 x 100 = 50m rows. If possible I'd like to use an approach using purrr::map.