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.

  • hash :: character(1)
    Returns a unique hash for this backend. This hash is cached.

  • data_formats :: character()
    Vector of supported data formats. A specific format of these supported formats can be picked in the $data() method.

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) b$head()
#> x1 x2 ..row_id #> 1: 0 1 row_1 #> 2: 1 1 row_2 #> 3: 0 0 row_3 #> 4: 1 0 row_4 #> 5: 0 0 row_5 #> 6: 0 0 row_6
b$data(b$rownames[1:3], b$colnames, data_format = "Matrix")
#> 3 x 2 sparse Matrix of class "dgCMatrix" #> x1 x2 #> row_1 . 1 #> row_2 1 1 #> row_3 . .