Why You Should Vectorize Your Code in R

Using the microbenchmark package in R to compare the efficiency between vectorized operations and for-loops

Andrea Gustafsen
Towards Data Science
4 min readNov 30, 2021

--

Photo by Vipul Jha on Unsplash

In this article, I will illustrate the benefits of using vectorized code by comparing how long it takes to perform three different tasks using vectorized operations versus using a for-loop for the same task. The…

--

--

Data Scientist | Statistician | I love books, trail running, gaming, and horror movies