na.dummy: Handle Missing Values with Fill + Dummy

Description Usage Arguments Author(s) References Examples

View source: R/na_dummy.R

Description

Handles missing values by filling in with mean, and adding a dummy variable.

Usage

1
2
3
na.dummy(object, ...)

fix_predvars(object)

Arguments

object

an R object, typically a data.frame

...

other arguments (not used)

Author(s)

Neal Fultz

References

https://stackoverflow.com/questions/54642599/impute-constant-and-create-missingness-dummy/54757973#54757973

Examples

1
2
3
4
5
6
7
8
9
df <- structure(list(Y = c(3.83, 22.73, 13.85, 14.09, 20.55, 18.51, 
17.76, 9.42, 15.88, 27.81), X1 = 1:10, X2 = c(2L, NA, NA, 4L, 
8L, 7L, 6L, 1L, 3L, 9L)), .Names = c("Y", "X1", "X2"), row.names = c(NA, 
-10L), class = "data.frame")

(m <- lm(Y~X1+X2, df, na.action = na.dummy))
m2 <- fix_predvars(m)
attr(terms(m2), "predvars")
predict(m2, newdata = data.frame(X1=2,X2=NA_real_))

stackoverflow documentation built on Jan. 10, 2020, 9:07 a.m.