DataBackend for Matrix. Data is stored as (sparse) matrix.

Format

R6::R6Class object inheriting from DataBackend.

Construction

DataBackendMatrix$new(data, primary_key = NULL)
  • data :: Matrix::Matrix().

  • primary_key :: character(1)
    Not supported by this backend. Rows are addresses by their rownames(). If the matrix does not have row names, integer row indices are used.

Alternatively, use as_data_backend on a Matrix::Matrix().

Fields

  • nrow :: integer(1)
    Number of rows (observations).

  • ncol :: integer(1)
    Number of columns (variables), including the primary key column.

  • colnames :: character()
    Returns vector of all column names, including the primary key column.

  • rownames :: integer() | character()
    Returns vector of all distinct row identifiers, i.e. the primary key column.

Methods

See also

Examples

#> Loading required namespace: Matrix
data = Matrix::Matrix(sample(0:1, 20, replace = TRUE), ncol = 2) colnames(data) = c("x1", "x2") rownames(data) = paste0("row_", 1:10) b = as_data_backend(data) print(b$head(n = 3, format = "data.table"))
#> x1 x2 ..row_id #> 1: 0 1 row_1 #> 2: 1 1 row_2 #> 3: 0 0 row_3
print(b$head(n = 3, format = "sparse"))
#> 3 x 2 sparse Matrix of class "dgCMatrix" #> x1 x2 #> row_1 . 1 #> row_2 1 1 #> row_3 . .