coerce_numeric_vars: Coerce columns to numeric, replacing non-numeric values with...

View source: R/QC_clean.R

coerce_numeric_varsR Documentation

Coerce columns to numeric, replacing non-numeric values with NA

Description

For each specified column, attempts to coerce the values to numeric. Values that cannot be coerced (e.g. character strings such as "hemolysed" appearing in an otherwise numeric column) are replaced with NA. A message lists the dropped values per column so the user is aware of what was discarded. Use suppressMessages() to silence.

Usage

coerce_numeric_vars(data, ...)

Arguments

data

A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr).

...

<dplyr_tidy_select> Columns to coerce. If none are supplied, data is returned unchanged.

Details

Columns that are already numeric are left untouched.

Value

data with the specified columns coerced to numeric.

Examples

df <- data.frame(x = c("1", "2", "hemolysed", "3"),
                 y = c("a", "b", "c", "d"))
coerce_numeric_vars(df, x)

eHDPrep documentation built on Oct. 21, 2026, 5:10 p.m.