pivot_to_matrix: Convert a data frame in long format to a matrix

pivot_to_matrixR Documentation

Convert a data frame in long format to a matrix

Description

Convert a data frame in long format to a matrix

Usage

pivot_to_matrix(data, rows_from, cols_from, values_from, fill = 0)

pivot_to_numeric_matrix(data, obs_col, feature_col, value_col)

Arguments

data

A data frame in long format.

rows_from

The column indicating the row of the matrix.

cols_from

The column indicating the column of the matrix.

values_from

The column indicating the value to be placed inside the matrix.

fill

The value to use for missing combinations of rows and columns.

obs_col, feature_col, value_col

The same as rows_from, cols_from, and values_from, respectively.

Details

The parameters rows_from, cols_from, and values_from should be provided as bare column names.

This function requires the packages tidyr, rlang, and tibble to be installed. If they are not installed, the function will generate an error, with a message to install the appropriate packages.

Functions

  • pivot_to_numeric_matrix(): Specialized version for numeric values. Deprecated; use pivot_to_matrix instead.

Examples

longdata <- data.frame(
  sample_id = paste0("Sample", c(1, 1, 1, 2, 2, 3, 3)),
  feature_id = paste0("Feature", c(1, 2, 3, 1, 2, 2, 3)),
  counts = c(132, 41, 7, 56, 11, 929, 83))
pivot_to_matrix(longdata, sample_id, feature_id, counts)

kylebittinger/usedist documentation built on June 1, 2024, 3:25 p.m.