gmp (version 0.7-4)

apply: Apply Functions Over Matrix Margins (Rows or Columns)

Description

These are S3 methods for apply() which we re-export as S3 generic function. They “overload” the apply() function for big rationals ("bigq") and big integers ("bigz").

Usage

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

Value

The bigz and bigq methods return a vector of class

"bigz" or "bigq", respectively.

Arguments

X

a matrix of class bigz or bigq, see e.g., matrix.bigz.

MARGIN

1: apply function to rows; 2: apply function to columns

FUN

function to be applied

...

(optional) extra arguments for FUN(), as e.g., in lapply.

Author

Antoine Lucas

See Also

apply; lapply is used by our apply() method.

Examples

Run this code
 x <- as.bigz(matrix(1:12,3))
 apply(x,1,min)
 apply(x,2,max)

 x <- as.bigq(x ^ 3, d = (x + 3)^2)
 apply(x,1, min)
 apply(x,2, sum)
 ## now use the "..." to pass  na.rm=TRUE :
 x[2,3] <- NA
 apply(x,1, sum)
 apply(x,1, sum, na.rm = TRUE)

Run the code above in your browser using DataLab