Steven Sanderson operates over a list of operators over lists:
In this post I will talk about the use of the R functions
apply()
,lapply()
,sapply()
,tapply()
, andvapply()
with examples.These functions are all designed to help users apply a function to a set of data in R, but they differ in their input and output types, as well as in the way they handle missing values and other complexities. By using the right function for your particular problem, you can make your code more efficient and easier to read.
I do prefer the purrr()
syntax because it’s a little easier to remember its function names versus keeping the variants of apply()
straight in your mind. Even so, there’s a lot you can do with a judicious use of apply()
.