Learn R Programming

dibble (version 0.3.0)

apply: Apply functions over array margins

Description

Applying a function to margins of a dibble or array, including a matrix.

Usage

apply(X, MARGIN, FUN, ...)

# S3 method for default apply(X, MARGIN, FUN, ..., simplify = TRUE)

# S3 method for tbl_ddf apply(X, MARGIN, FUN, ...)

# S3 method for ddf_col apply(X, MARGIN, FUN, ...)

Value

A dibble if X is a dibble. See base::apply() for the return value of the default method.

Arguments

X

A dibble or array, including a matrix.

MARGIN

An integer or character vector giving the subscripts which the function will be applied over.

FUN

A function to be applied.

...

Optional arguments to FUN.

simplify

A logical indicating whether results should be simplified if possible.

Details

apply() overrides base::apply() to make it generic. The default method calls the base version.

See Also

Examples

Run this code
x <- array(1:24, 2:4,
           list(axis1 = letters[1:2],
                axis2 = letters[1:3],
                axis3 = letters[1:4]))

apply(x, 2:3, sum)
apply(as_dibble(x), 2:3, sum)

apply(x, c("axis2", "axis3"), sum)
apply(as_dibble(x), c("axis2", "axis3"), sum)

Run the code above in your browser using DataLab