Tapply | R Documentation |
Applies a function, typically to compute a single statistic, like a mean, median, or standard deviation,
within levels of a factor or within combinations of levels of two or more factors to produce a table of statistics. This function provides
a formula interface to the standard R tapply
function.
Tapply(formula, fun, data, na.action = na.pass, ..., targs = list())
formula |
a two-sided formula of the form |
fun |
a function, like |
data |
an optional data frame within which to find the variable and factor(s). |
na.action |
a function to handle missing values, as in statistical modeling functions like |
... |
arguments to pass to the function given in the |
targs |
a list of optional arguments to pass to |
The function given by fun
is applied to the values of the left-hand-side variable in formula
within
(combination of) levels of the factor(s) given in the right-hand side of formula
, producing a table of statistics.
The object returned by tapply
, typically simply printed.
John Fox jfox@mcmaster.ca
Fox, J. and Weisberg, S. (2019) An R Companion to Applied Regression, Third Edition. Sage.
tapply
.
Tapply(conformity ~ partner.status + fcategory, mean, data=Moore)
Tapply(conformity ~ partner.status + fcategory, mean, data=Moore,
trim=0.2)
Moore[1, 2] <- NA
Tapply(conformity ~ partner.status + fcategory, mean, data=Moore)
Tapply(conformity ~ partner.status + fcategory, mean, data=Moore,
na.rm=TRUE)
Tapply(conformity ~ partner.status + fcategory, mean, data=Moore,
na.action=na.omit) # equivalent
remove("Moore")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.