top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

R: Difference between apply vs sapply vs lapply vs tapply?

+3 votes
5,637 views

What are the differences between following functions in R?

posted Feb 11, 2015 by Khusboo

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

apply - When you want to apply a function to the rows or columns or both of a matrix and output is a one-dimensional if only row or column is selected else it is a 2D-matrix
lapply - When you want to apply a function to each element of a list in turn and get a list back.
sapply - When you want to apply a function to each element of a list in turn, but you want a vector back, rather than a list.
tapply - When you want to apply a function to subsets of a vector and the subsets are defined by some other vector, usually a factor.

answer Feb 12, 2015 by Salil Agrawal
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...