\donttest{
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)
}sweep.HDF5Matrix
sweep.HDF5Matrix
OTHER
1 Description
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.
2 Usage
sweep.HDF5Matrix(...)3 Arguments
| Parameter | Description |
|---|---|
x |
An (the matrix to sweep over). |
MARGIN |
Integer. (default, sweep over columns) or (sweep over rows). Corresponds to : means . |
STATS |
An with one row or one column (the vector to broadcast). Must be in the same HDF5 file as . |
FUN |
Character. Operation: , , (default), , . |
check.margin |
Ignored (kept for S3 signature compatibility). |
paral |
Logical or NULL. |
threads |
Integer or NULL. |
compression |
Integer (0-9) or NULL. |
4 Value
A new .