Learn R Programming

PubChemR (version 3.0.0)

pc_model_matrix: Convert Feature Tables to Model Matrix Form

Description

Converts tabular PubChem features into a numeric model-matrix bundle with optional outcome and identifier metadata.

Usage

pc_model_matrix(
  x,
  outcome = NULL,
  id_cols = c("CID", "SID", "AID", "Identifier"),
  na_fill = NULL,
  scale = FALSE
)

Value

An object of class `PubChemModelMatrix` with `x`, `y`, and metadata fields.

Arguments

x

Input table or `PubChemResult`.

outcome

Optional outcome column name.

id_cols

Identifier columns excluded from predictors.

na_fill

Optional numeric value used to fill missing predictor values.

scale

Logical; center and scale predictor matrix.

Details

Non-numeric predictors are coerced when feasible, then filtered to numeric columns only. The returned object stores predictors, optional response, and identifier columns.

Examples

Run this code
tbl <- tibble::tibble(CID = c("1", "2"), x1 = c("1.0", "2.0"), y = c(0, 1))
mm <- pc_model_matrix(tbl, outcome = "y")
class(mm)

Run the code above in your browser using DataLab