Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the t in tapply stand for?

Tags:

r

tapply

There seems to be general agreement that the l in "lapply" stands for list, the s in "sapply" stands for simplify and the r in "rapply" stands for recursively. But I could not find anything on the t in "tapply". I am now very curious.

like image 659
orizon Avatar asked Apr 21 '15 23:04

orizon


People also ask

What is tapply command in R?

tapply in R. Apply a function to each cell of a ragged array, that is to each (non-empty) group of values given by a unique combination of the levels of certain factors. Basically, tapply() applies a function or operation on subset of the vector broken down by a given factor variable.

What is the difference between Sapply and Lapply?

Difference between lapply() and sapply() functions:lapply() function displays the output as a list whereas sapply() function displays the output as a vector. lapply() and sapply() functions are used to perform some operations in a list of objects.

What is Sapply?

sapply() function in R Language takes list, vector or data frame as input and gives output in vector or matrix. It is useful for operations on list objects and returns a list object of same length of original set.


2 Answers

Stands for table since tapply is the generic form of the table function. You can see this by comparing the following calls:

x <- sample(letters, 100, rep=T)
table(x)
tapply(x, x, length)

although obviously tapply can do more than counting.

Also, some references that refer to "table-apply":

  • R and S Plus companion
  • Modern Applied Biostatistical Methods
like image 125
BrodieG Avatar answered Oct 18 '22 23:10

BrodieG


I think of it as 'table'-apply since the result comes as a matrix/table/array and its dimensions are established by the INDEX arguments. An R table-classed object is really very similar in contrcution and behavior to an R matrix or array. The application is being performed in a manner similar to that of ave. Groups are first assembled on the basis of the "factorized" INDEX argument list (possibly with multiple dimensions) and a matrix or array is returned with the results of the FUN applied to each cross-classified grouping.

The other somewhat similar function is 'xtabs'. I keep thinking it should have a "FUN" argument, but what I'm probably forgetting at that point is really tapply.

like image 5
IRTFM Avatar answered Oct 18 '22 22:10

IRTFM