apply vs for
It’s widely understood that, in R programming, one should avoid
for loops and always try to use
But this isn’t entirely true. It may have been true for Splus, back in the day: As I recall, that had to do with the entire environment from each iteration being retained in memory.
Here’s a simple example:
They say that
apply can be more readable. It can certainly be more compact, but I usually find a
for loop to be more readable, perhaps because I’m a C programmer first and an R programmer second.
A key point, from Ligges and…
View original post 18 more words