Selina Cheng explains how the various apply() functions work:
Today I’m going to talk about a useful family of functions that allows you to repetitively perform a specified function (e.g.,
sum()
,mean()
) across a vector, list, matrix, or data frame. For those of you familiar with ‘for’ loops, theapply()
family often allows you to avoid constructing those and instead wrap the loop into one simple function.I’m going to discuss the functions
apply()
,lapply()
,sapply()
, andtapply()
in this blog post (as well as using the dplyr library for similar tasks). These functions all end inapply()
because you apply the function you want across all the specified elements.
Read on to see how these functions work. H/T R-Bloggers.
Comments closed