| sweep.HDF5Matrix | R Documentation |
S3 method of base::sweep() for HDF5Matrix objects.
Broadcasts a 1-row HDF5Matrix (acting as the STATS vector)
across every row or column of the matrix, element-wise.
## S3 method for class 'HDF5Matrix'
sweep(
x,
MARGIN = 2L,
STATS,
FUN = "*",
check.margin = TRUE,
paral = NULL,
threads = NULL,
compression = NULL,
...
)
x |
An |
MARGIN |
Integer. |
STATS |
An |
FUN |
Character. Operation: |
check.margin |
Ignored (kept for S3 signature compatibility). |
paral |
Logical or NULL. |
threads |
Integer or NULL. |
compression |
Integer (0-9) or NULL. |
... |
Ignored. |
A new HDF5Matrix.
fn <- tempfile(fileext = ".h5")
mat <- matrix(rnorm(100), 10, 10)
X <- hdf5_create_matrix(fn, "data/X", data = mat)
# STATS must be an HDF5Matrix with one row or one column
# Create a 1-row vector with column means
col_means_vec <- colMeans(as.matrix(X))
stats_hdf5 <- hdf5_create_matrix(fn, "data/col_means",
data = matrix(col_means_vec, 1, 10))
# Column-center X (MARGIN = 2)
X_c <- sweep(X, 2, stats_hdf5, "-")
# Verify first column is centered
all.equal(as.matrix(X_c)[, 1],
mat[, 1] - col_means_vec[1])
hdf5_close_all()
unlink(fn)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.