[英]Extract dataframe from lm model object
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.我正在寻找一个函数,该函数从
lm
模型对象中提取用作输入的数据框的名称。
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.frame()
错误,否则它只会为我提供包含模型中使用的术语的数据框,而不是原始输入数据框。
model$call$data
gives you mtcars
(an unevaluated symbol); model$call$data
给你mtcars
(一个未mtcars
的符号); deparse(model$call$data)
gives you "mtcars"
(a string). deparse(model$call$data)
给你"mtcars"
(一个字符串)。 eval(model$call$data)
gives you back the original data object, if it is available in the current environment. eval(model$call$data)
返回原始数据对象,如果它在当前环境中可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.