h_df_factors_with_explicit_na: Conversion to Factors with Explicit Missing Level in a...

View source: R/utils.R

h_df_factors_with_explicit_naR Documentation

Conversion to Factors with Explicit Missing Level in a data.frame

Description

[Experimental]

This helper function converts all character and logical variables to factor variables in a data.frame. It also sets an explicit missing data level for all factor variables that have at least one NA. Empty strings are handled as NA.

Usage

h_df_factors_with_explicit_na(data, na_level = "<Missing>")

Arguments

data

(data.frame)
input data with at least one column.

na_level

(string)
explicit missing level to be used.

Value

The modified data.

Examples

dat <- data.frame(
  a = c(NA, 2),
  b = c("A", NA),
  c = c("C", "D"),
  d = factor(c(NA, "X")),
  e = factor(c("Y", "Z"))
)
h_df_factors_with_explicit_na(dat)

insightsengineering/hermes documentation built on Sept. 19, 2024, 9:06 p.m.