pivot_to_numeric_matrix: Convert a data frame in long format to a numeric matrix

Description Usage Arguments Examples

Description

Convert a data frame in long format to a numeric matrix

Usage

1
pivot_to_numeric_matrix(data, obs_col, feature_col, value_col)

Arguments

data

A data frame with numerical values in long format.

obs_col

The column listing the observation, or row of the matrix.

feature_col

The column listing the feature, or column of the matrix.

value_col

The column listing the value, to be placed inside the matrix.

The parameters obs_col, feature_col, and value_col should be provided as bare column names. If any combination of row and column does not appear in the data frame, a zero will be entered in the resultant matrix.

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

Examples

1
2
3
4
5
6
longdata <- data.frame(
  SampleID = paste0("Sample", c(1, 1, 1, 2, 2, 3, 3)),
  FeatureID = paste0("Feature", c(1, 2, 3, 1, 2, 2, 3)),
  Value = c(132, 41, 7, 56, 11, 929, 83))
longdata
pivot_to_numeric_matrix(longdata, SampleID, FeatureID, Value)

usedist documentation built on March 2, 2020, 1:07 a.m.