Skip to contents

Replaces NA or specified values in selected columns of a data.table. Use for cleaning survey or model data before analysis.

Usage

fillna(dt, value, cols = NULL, na_value = NULL)

Arguments

dt

data.table. Input to fill.

value

scalar. Value to fill in place of NA or na_value.

cols

character vector, optional. Columns to fill (default all).

na_value

scalar, optional. Value to replace (default NA).

Value

data.table. Copy of input with filled values.

Details

  • Fills NA or specified value (e.g., 995) with replacement value.

  • Can target specific columns or all columns.

  • Returns a copy; does not modify by reference.

Settings

None.

See also

clip.vector

Other utility functions: archive_file(), clip.vector(), weighted.median(), weighted.percentile()

Examples

dt <- data.table(a = c(NA, 1, 2), b = c(995, NA, 3))
fillna(dt, value = 0, na_value = 995)
#>        a     b
#>    <num> <num>
#> 1:    NA     0
#> 2:     1    NA
#> 3:     2     3