

Suppose we want to calculate the average height or average weight by gender of the respondent. Let us create a sample data frame to understand the use of tapply() function on data frame. tapply() function on data frame Example 1: tapply() function on data frame That is, the function tapply() applies FUN on X grouped by factors in INDEX. The function tapply(X, INDEX,FUN) split the data of X into subgroups based on the levels of INDEX variable, then apply the function FUN to each subgroup of the data. simplify: If FALSE, tapply returns an array of mode list.INDEX: list of one or more factor each of same length as X.X: an atomic object, typically a vector.The general syntax of tapply() function is tapply(X, INDEX,FUN=NULL.,simplify=TRUE)

That is tapply() function allows us to create a group summaries based on factor levels. The tapply() function is very useful to aggregate the data. tapply() function is available in base R package. In this tutorial, we will discuss about tapply() function in R with some examples. 2.5 Example 5: tapply() Function with multiple factors.2.4 Example 4: Simplified result using tapply() Function.2.3 Example 3: tapply() Function with user-defined function.2.2 Example 2 : quantiles using tapply() function on data frame.2.1 Example 1: tapply() function on data frame.
