sub-.HDF5Matrix: Subset an HDF5Matrix

[.HDF5MatrixR Documentation

Subset an HDF5Matrix

Description

Subset an HDF5Matrix

Usage

## S3 method for class 'HDF5Matrix'
x[i, j, drop = TRUE, ...]

Arguments

x

An HDF5Matrix object

i

Row indices: numeric, integer, logical, or missing

j

Column indices: numeric, integer, logical, or missing

drop

Logical, whether to drop dimensions for single row/column results (default TRUE)

...

Ignored

Details

All standard R indexing modes are supported:

  • Contiguous ranges: X[1:100, 1:50]

  • Non-contiguous: X[c(1,3,5), c(2,4)]

  • Negative: X[-c(1,2), ] (all except rows 1 and 2)

  • Logical: X[row_mask, col_mask]

  • Missing: X[, ] (entire dataset)

Value

Numeric matrix, or vector when drop = TRUE and one dimension has length 1

Examples


tmp <- tempfile(fileext = ".h5")

X  <- hdf5_create_matrix(tmp, "data/matrix", data = matrix(rnorm(100), 10, 10))
X <- hdf5_matrix(tmp, "data/matrix")

X[1:5, 1:3]               # submatrix
X[1, ]                    # single row as vector
X[1, , drop = FALSE]      # single row as matrix
X[, 2]                    # single column as vector
X[-c(1, 10), ]            # all except first and last row
X[c(TRUE, FALSE), ]       # logical row index
X[, ]                     # entire dataset

X$close()
unlink(tmp)



BigDataStatMeth documentation built on May 15, 2026, 1:07 a.m.