Learn R Programming

salad (version 1.2)

apply,dual-method: Apply functions over array margins of dual objects

Description

This method generalizes `base::apply` to dual objects.

Usage

# S4 method for dual
apply(X, MARGIN, FUN, ..., simplify = TRUE)

Value

The returned value depends on the values returned by `FUN`, similarly to `base::apply`

Arguments

X

a dual object (with array or matrix shape)

MARGIN

a vector giving the subscript which the function will be applied over

FUN

the function to be applied

...

extra arguments for `FUN`

simplify

a logical indicating whether the results should be simplified

See Also

Examples

Run this code
A <- matrix( c(1,2,3,4), 2, 2)
x <- dual(A)
cs <- apply(x, 2, sum)
cs
d(cs)
# prefered method for summing over the columns
colSums(x) 

Run the code above in your browser using DataLab