I have a simple example of foreach nested loop below. How can I improve the readability of the result res
?
Below is another example of nested for loop with more readable results, each element of list can be easily identified e.g. res_desired[["B"]][[3]]
library(foreach)
library(doFuture)
registerDoFuture()
plan(multicore, workers = 1)
# foreach loop
res <- foreach(a = c("A", "B", "C", "D")) %:%
foreach(b = 1:4) %do%
{
paste0(rep(a, b))
}
# for loop
res_desired <- list()
for(a in c("A", "B", "C", "D"))
{
for(b in 1:4)
{
res_desired[[a]][[b]] <- paste0(rep(a, b))
}
}