Learn R Programming

pbdDMAT (version 0.2-3)

Apply: Apply Family of Functions

Description

Apply a function to the margins of a distributed matrix.

Usage

## S3 method for class 'ddmatrix':
apply(X, MARGIN, FUN, ..., reduce = FALSE, 
proc.dest="all")

Arguments

X
distributed matrix
MARGIN
subscript over which the function will be applied
FUN
the function to be applied
...
additional arguments to FUN
reduce
logical or string. See details
proc.dest
Destination process (or 'all') if a reduction occurs

Value

  • Returns a distributed matrix unless a reduction is requested, then a global matrix/vector is returned.

Details

If reduce==TRUE then a global matrix or vector (whichever is more appropriate) will be returned. The argument proc.dest= behaves exactly as in the as.vector() and as.matrix() functions of pbdDMAT. If reduce=FALSE then a distributed matrix is returned. Other acceptable arguments are reduce="matrix" and reduce="vector" which demand global matrix or vector return, respectively. This should generally be slightly more efficient than running apply and then calling as.vector() or as.matrix().

See Also

prcomp

Examples

Run this code
# Save code in a file "demo.r" and run with 2 processors by
# > mpiexec -np 2 Rscript demo.r

library(pbdDMAT, quiet = TRUE)
init.grid()

# don't do this in production code
x <- matrix(1:9, 3)
x <- as.ddmatrix(x)

y <- head(x[, -1], 2)
print(y)

finalize()

Run the code above in your browser using DataLab