simApply: Apply a function to subsets

Description Usage Arguments Value Methods for function simApply Methods for function simSapply Author(s) See Also Examples

Description

Generic functions for applying a function to subsets of a data set.

Usage

1
2
3
simApply(x, design, fun, ...)

simSapply(x, design, fun, ..., simplify = TRUE)

Arguments

x

the data.frame to be subsetted.

design

a character, logical or numeric vector specifying the variables (columns) used for subsetting.

fun

a function to be applied to the subsets.

simplify

a logical indicating whether the results should be simplified to a vector or matrix (if possible).

...

additional arguments to be passed to fun.

Value

For simApply a data.frame.

For simSapply, a list, vector or matrix (see sapply).

Methods for function simApply

x = "data.frame", design = "BasicVector", fun = "function"

apply a function to subsets given by the variables (columns) in design.

x = "data.frame", design = "Strata", fun = "function"

apply a function to subsets given by design.

Methods for function simSapply

x = "data.frame", design = "BasicVector", fun = "function"

apply a function to subsets given by the variables (columns) in design.

x = "data.frame", design = "Strata", fun = "function"

apply a function to subsets given by design.

Author(s)

Andreas Alfons

See Also

sapply

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
data(eusilcP)
eusilcP <- eusilcP[, c("region", "gender", "eqIncome")]

## returns data.frame
simApply(eusilcP, c("region", "gender"), 
    function(x) median(x$eqIncome))

## returns vector
simSapply(eusilcP, c("region", "gender"), 
    function(x) median(x$eqIncome))

simFrame documentation built on Oct. 14, 2021, 5:24 p.m.