This week I was trying to optimize some R code. The code involved a lot of loops to traverse a large data frame, so I thought was a good idea to first look at all my options and then decide what is the best way for me to implement such loops.
There are many ways to loops across datasets in R. Many times it is not even necessary to write a loop. For example if you just want to sum across columns in a data.frame, or get the mean, s.d. etc, there are functions such as
colMeans() among others. However, lets look at the options next.