R code is often quick to write, but not always quick enough to run. One strategy to speed up runtimes is to parallelize code. Here, we create 200 regression models using 200 different predictors - a task well suited for parallelization.
First, we set up the workers using makeCluster(). Next, we create a function that takes a predictor as input and returns a model summary. Then we can create all 200 models with a simple one-liner using lapply(). To parallelize, we have to overcome a small challenge, namely provide the workers with data using clusterExport(). Then we can simply exchange lapply() for clusterApply() to run our code in parallel.
The bench::mark() function shows the speed improvement that gave us.
Code can be found here:
[ Ссылка ]
All the best for speeding up your R code!
Thumbnail image: Chait Goli from Pexels
Contact me, e. g. to discuss (online) R workshops / trainings / webinars:
LinkedIn: [ Ссылка ]
Twitter: [ Ссылка ]
Xing: [ Ссылка ]
Facebook: [ Ссылка ]
[ Ссылка ]
R Workshops: [ Ссылка ]
Blog (German, translate option): [ Ссылка ]
Playlist: Music chart history
[ Ссылка ]
Ещё видео!