The for-loop in R, can be very slow in its raw un-optimised form, especially when dealing with larger data sets. There are a number of ways you can make your logics run fast, but you will be really surprised how fast you can actually go.

This posts shows a number of approaches including simple tweaks to logic design, parallel processing and Rcpp , increasing the speed by orders of several magnitudes, so you can comfortably process data as large as 100 Million rows and more.

I am going to show you the various approaches using an example logic that involves a for-loop and a condition checking statement (if-else) to create a column that gets appended to a sufficiently large data frame (df). Lets begin by creating that initial dataframe.