Jan. 12, 2022, 8:42 p.m. | Andrea Gustafsen

Towards Data Science - Medium towardsdatascience.com

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

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 microbenchmark package in R provides a handy tool to compare how long different R expressions take to execute.

The code used in this article …

code data science for-loop vectorize

Senior Marketing Data Analyst

@ Amazon.com | Amsterdam, North Holland, NLD

Senior Data Analyst

@ MoneyLion | Kuala Lumpur, Kuala Lumpur, Malaysia

Data Management Specialist - Office of the CDO - Chase- Associate

@ JPMorgan Chase & Co. | LONDON, LONDON, United Kingdom

BI Data Analyst

@ Nedbank | Johannesburg, ZA

Head of Data Science and Artificial Intelligence (m/f/d)

@ Project A Ventures | Munich, Germany

Senior Data Scientist - GenAI

@ Roche | Hyderabad RSS