freplace_na: Replaces NA's with specified values.

View source: R/freplace_na.R

freplace_naR Documentation

Replaces NA's with specified values.

Description

Some the downstream uses of a FacilexStore can throw problems when NA's are found in x or covariates, so we often want to fill in NA's with non-NA markers of missing values. Note that unless specified otherwise (using the replace and defaults parameters),

Usage

freplace_na(x, replace = list(), defaults = list(), ignore = character(), ...)

Arguments

x

the thing that has NA's in it (a data.frame, list, or vector)

replace

a named list of elements to use for custom replacement values

defaults

if named elements in x do not appear in replace, you can provide default values for categories of parameters (ie. "categorical" or "numeric"), otherwise FacileData:::defaults.freplace_na will be used.

ignore

the names of columns (or elements in a list)

Details

Depending on the atomic type of the thing that NA's are being replaced with, a default value is assumed. These can be overriden by using the defaults parameter, or specifically by column (or list) names via the replace parameter.

Missing values (NA's) come up often in FacilexStores since we often use them to include x from multiple xsets, which induces "ragged" (sparse) covariate (px) entries. In man

Value

an data-replaced version of x

Examples

data <- data.frame(
  a = rnorm(10),
  b = letters[1:10],
  c = factor(LETTERS[1:10]))
data[3, ] <- NA
r1 <- freplace_na(data, list(b = "bee"), ignore = "a")
r2 <- freplace_na(data, list(b = "bee"), defaults = list(numeric = -Inf))

facilebio/FacileData documentation built on Feb. 23, 2024, 9:14 a.m.