maggregate | R Documentation |
Compute function on subsets of a variable in a data frame.
maggregate(
formula,
data = parent.frame(),
FUN,
groups = NULL,
subset,
drop = FALSE,
...,
.format = c("default", "table", "flat"),
.overall = mosaic.par.get("aggregate.overall"),
.multiple = FALSE,
.name = deparse(substitute(FUN)),
.envir = parent.frame()
)
formula |
a formula. Left side provides variable to be summarized. Right side and condition describe subsets. If the left side is empty, right side and condition are shifted over as a convenience. |
data |
a data frame.
Note that the default is |
FUN |
a function to apply to each subset |
groups |
grouping variable that will be folded into the formula (if there is room for it). This offers some additional flexibility in how formulas can be specified. |
subset |
a logical indicating a subset of |
drop |
a logical indicating whether unused levels should be dropped. |
... |
additional arguments passed to |
.format |
format used for aggregation. |
.overall |
currently unused |
.multiple |
a logical indicating whether FUN returns multiple values
Ignored if |
.name |
a name used for the resulting object |
.envir |
an environment in which to evaluate expressions |
a vector
if (require(mosaicData)) {
maggregate( cesd ~ sex, HELPrct, FUN = mean )
# using groups instead
maggregate( ~ cesd, groups = sex, HELPrct, FUN = sd )
# the next four all do the same thing
maggregate( cesd ~ sex + homeless, HELPrct, FUN = mean )
maggregate( cesd ~ sex | homeless, HELPrct, FUN = sd )
maggregate( ~ cesd | sex , groups= homeless, HELPrct, FUN = sd )
maggregate( cesd ~ sex, groups = homeless, HELPrct, FUN = sd )
# this is unusual, but also works.
maggregate( cesd ~ NULL , groups = sex, HELPrct, FUN = sd )
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.