Simple question for which I haven't been able to find the answer.
I'm looking for a function that extracts the name of the data frame used as input from an lm model object.
So for example, if I run
model <- lm(mpg ~ cyl, data = mtcars)
I want a function like
data.name(model)
that produces
mtcars
I've looked here and here but they don't seem to be giving me what I'm looking for. For example, unless I'm using model.frame() wrong, it just gives me the data frame with the terms used in the model, not the original input data frame.
model$call$data gives you mtcars (an unevaluated symbol); deparse(model$call$data) gives you "mtcars" (a string). eval(model$call$data) gives you back the original data object, if it is available in the current environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With