R PROGRAMING lapply FUNCTION TUTORIAL

Опубликовано: 22 Апрель 2026
на канале: Art of Visualization
8,680
94

Learn all about R programming lapply function through this amazing tutorial!

lapply
lapply returns a list of the same length as X, each element of which is the result of applying FUN to the corresponding element of X.
Usage:
lapply(X, FUN, …)
Arguments:
X
a vector (atomic or list) or an expression object. Other objects (including classed objects) will be coerced by base::as.list.

FUN
the function to be applied to each element of X: see ‘Details’. In the case of functions like +, %*%, the function name must be backquoted or quoted.


optional arguments to FUN.

You want to apply a given function to every element of a list and obtain a list as a result. When you execute ?lapply, you see that the syntax looks like the apply() function.

The difference is that:

It can be used for other objects like dataframes, lists or vectors; and
The output returned is a list (which explains the “l” in the function name), which has the same number of elements as the object passed to it.

To stay up to date with our latest videos make sure to subscribe to this YouTube channel!