Explain how apply() and lapply() function works in R.

479    Asked by Natunyadav in Data Science , Asked on Nov 19, 2019
Answered by Natun yadav

Apply() function works by considering input as a data frame or a matrix and gives an output as a vector, list or an array.

apply() function basically takes 3 arguments which are

  1. Array or a matrix
  2. A value to define the function
  3. A function to apply.

lapply() function works only on lists and it also returns output as a form of list. Basically it applies a function to work on a list and it doesn't need a margin.

apply() function returns an output as a vector but lappy() returns output as a list.

Your Answer


Parent Categories