Learn R Programming

EpiForsk (version 0.2.0)

DiscreteCovariateNames: Extract discrete covariate names

Description

Detect elements in covariates which match a string from the discrete_covariates argument.

Usage

DiscreteCovariateNames(covariates, discrete_covariates = NULL)

Value

A character vector with elements from covariates matching the names supplied in discrete_covariates.

Arguments

covariates

character, names of covariates

discrete_covariates

character, names of discrete covariates. Currently it is assumed that discrete covariates are one-hot encoded with naming in covariates following {fct_nm}_{lvl_nm}.

Author

KIJA

Examples

Run this code
one_hot_df <- mtcars |>
  dplyr::mutate(across(c(2, 8:11), factor)) |>
  as.data.frame() |>
  DiscreteCovariatesToOneHot(cyl)
EpiForsk:::DiscreteCovariateNames(colnames(one_hot_df), c("cyl"))

Run the code above in your browser using DataLab