Learn R Programming

OpasnetUtils (version 1.3)

oapply: Apply for ovariables

Description

Use tapply on the output slot

Usage

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

Arguments

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

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.

Details

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

Examples

Run this code
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)

Run the code above in your browser using DataLab