O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The lapply function accepts three arguments: the first argument is the object, the second is the user-specified function, and the optional third argument specifies the additional arguments to the user-specified function. The lapply function always returns a list, irrespective of the type of the first argument.

In step 1, the lapply function is used to apply sqrt to each element of a vector. The lapply function always returns a list.

In step 2, a list with three elements is involved, each of which is a vector. It calculates the mean of these vectors. The lapply function returns a list while sapply returns a vector in this case.

In step 3, sapply is used to apply a function to columns of a data frame. For obvious reasons, we ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required