3 R tips for loops

Tip 1: Avoid loops.
They are generally slow – use a function instead. Even with the need of variable and fixed columns in a loop, a function may be constructed like

Tip 2: Always show current state.
Include options(warn=1) and show current state with cat(“message\n”);flush.console();

Tip 3: Avoid merging steps.
Use instead datasets in same order and with the same subset of the larger table before updating anew column with data from the second table.