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

apply {gmp} | R Documentation

## 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 class 'bigz'
    apply(X, MARGIN, FUN, ...)
    ## S3 method for class 'bigq'
    apply(X, MARGIN, FUN, ...)

### 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`.

### Value

The `bigz` and `bigq` methods return a vector of class `"bigz"` or `"bigq"`, respectively.

### Author(s)

Antoine Lucas

### See Also

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

### Examples

     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)

[Package gmp version 0.6-2 Index]