There are many online resources for creating efficient R code, as well as our How to Learn R article, so we will just list the key concepts:
- Avoid using
foror lots ofifstatements in your R code. - Exploit R's vectorized calculations.
- Use
apply,sapply,lapply,vapply,apply, andaggregate. - Avoid using Hadleyverse functions for general data manipulation unless you have no other option. E.g., avoid
dplyr. (Much of the Hadleyverse is designed for making code "easy" to read, not for making code fast.)