Advanced constructs

We heard the term vectorized earlier when we talked about operating on vectors without using loops. While looping is a great way to iterate through vectors and perform computations, it is not very efficient when we deal with what is known as Big Data. In this case, R provides some advanced constructs which we will be looking at in this section. We will be covering the following functions:

  • lapply: Loops over a list and evaluates a function on each element
  • sapply: A simplified version of lapply
  • apply: Evaluates a function on the boundaries or margins of an array
  • tapply: Evaluates a function over subsets of a vector
  • mapply: A multivariate version of lapply

lapply and sapply

Like we mentioned earlier, lapply takes a list and a function ...

Get R Machine Learning By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.