Learn R Programming

PubChemR (version 3.0.0)

pc_activity_matrix: Build an Assay Activity Matrix

Description

Converts long-form assay activity data into dense or sparse matrix-ready representations indexed by compound and assay identifiers.

Usage

pc_activity_matrix(
  x,
  cid_col = "CID",
  aid_col = "AID",
  outcome_col = "ActivityOutcome",
  value_map = c(Active = 1, Inactive = 0, Inconclusive = NA_real_),
  strict_outcome = FALSE,
  unknown_outcome = NA_real_,
  fill = NA_real_,
  prefix = "AID_",
  aggregate = c("max", "mean", "first"),
  output = c("tibble", "sparse")
)

Value

A wide tibble (`output = "tibble"`) or a sparse matrix wrapper object of class `PubChemSparseActivityMatrix` (`output = "sparse"`).

Arguments

x

A long-form table or `PubChemResult` with at least CID/AID/outcome columns.

cid_col

Column name containing compound identifiers.

aid_col

Column name containing assay identifiers.

outcome_col

Column name containing activity outcome values.

value_map

Named numeric mapping for character outcomes.

strict_outcome

Logical. If `TRUE`, unknown outcome labels raise an error.

unknown_outcome

Numeric fallback for unknown labels when `strict_outcome = FALSE`.

fill

Fill value for missing matrix cells.

prefix

Prefix used for assay columns in wide format output.

aggregate

Aggregation method for repeated CID/AID pairs.

output

Output type: `"tibble"` (default dense table) or `"sparse"` (Matrix backend).

Details

Character outcomes are normalized through `pc_activity_outcome_map()`. For repeated CID/AID pairs, values are aggregated using the selected strategy.

Examples

Run this code
long_tbl <- tibble::tibble(
  CID = c("1", "1", "2"),
  AID = c("10", "11", "10"),
  ActivityOutcome = c("Active", "Inactive", "Active")
)
pc_activity_matrix(long_tbl)

Run the code above in your browser using DataLab