Explain how apply() and lapply() function works in R.
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
- Array or a matrix
- A value to define the function
- 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.