
Last chance! 50% off unlimited learning
Sale ends in
na.action
and
subset
arguments are applied and allows, for example, x
to be recovered for a model using sin(x)
as a predictor.
expand.model.frame(model, extras, envir = environment(formula(model)), na.expand = FALSE)
na.expand = FALSE
then NA
values in the extra variables
will be passed to the na.action
function used in
model
. This may result in a shorter data frame (with
na.omit
) or an error (with na.fail
). If
na.expand = TRUE
the returned data frame will have precisely the
same rows as model.frame(model)
, but the columns corresponding to
the extra variables may contain NA
.
model.frame
, predict
model <- lm(log(Volume) ~ log(Girth) + log(Height), data = trees)
expand.model.frame(model, ~ Girth) # prints data.frame like
dd <- data.frame(x = 1:5, y = rnorm(5), z = c(1,2,NA,4,5))
model <- glm(y ~ x, data = dd, subset = 1:4, na.action = na.omit)
expand.model.frame(model, "z", na.expand = FALSE) # = default
expand.model.frame(model, "z", na.expand = TRUE)
Run the code above in your browser using DataLab