Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

na.dummy

Handle Missing Values with Fill + Dummy


Description

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

Usage

na.dummy(object, ...)

fix_predvars(object)

Arguments

object

an R object, typically a data.frame

...

other arguments (not used)

Author(s)

References

Examples

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

Stack Overflow's Greatest Hits

v0.7.0
CC BY-SA 4.0
Authors
Neal Fultz <nfultz@gmail.com> and the StackOverflow.com community
Initial release
2020-01-03

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.