oapply: Apply for ovariables

Description Usage Arguments Details Value Author(s) Examples

View source: R/Oapply.r

Description

Use tapply on the output slot

Usage

1
2
3
oapply(X, INDEX = NULL, FUN = NULL, cols = NULL, drop_na = TRUE, 
    use_aggregate = TRUE, ..., simplify = TRUE)
ooapply(X, cols, FUN = "sum", ...)

Arguments

X

an ovariable

INDEX

list of factors, like tapply

FUN

function to apply, ooapply takes character input (Only "sum", "mean", "min", "max" and "prod" allowed.)

cols

names of columns to be removed (reverse INDEX)

drop_na

if TRUE removes NA from the result automatically

use_aggregate

if TRUE uses aggregate to perform apply, which is considerably faster with sparse variables

...

optional arguments to FUN

simplify

like tapply

Details

See also: http://en.opasnet.org/

Value

Returns an ovariable, with output slot tapplied and marginal adjusted accordingly. ooapply is a memory-saving variant of oapply when there is exactly one row for each unique combination. oapply with use_aggregate is fastest in most cases. Any extraneous columns are lost, as with tapply and aggregate.

Author(s)

T. Rintala [email protected]

Examples

1
2
3
4
a <- new("ovariable", name = "a", output = data.frame(A = c("a", "a", "b", "b"), 
    B = c("1", "2", "1", "2"), aResult = 1:4), marginal = c(TRUE, TRUE, FALSE))
oapply(a, FUN = sum, cols = "A")
oapply(a, a@output[c("A")], sum)

OpasnetUtils documentation built on July 4, 2017, 9:44 a.m.