Efficient `reduce` in R
Table of Contents
When you need to do a Reduce
operation on a list, it’s more efficient to use do.call()
.
Combining rows
a = lapply(1:100, rnorm, n = 50)
microbenchmark(Reduce(rbind, a),
do.call(rbind, a)) %>%
boxplot(unit = 'ms', boxwex=0.2)
Combining columns
microbenchmark(Reduce(cbind, a),
do.call(cbind, a)) %>%
boxplot(unit = 'ms', boxwex = 0.2)