get_model | R Documentation |
This functions tries to get a model object from the object x
,
where the model object is saved as an (arbitrarily named) attribute. This is
useful for example, when a model is fitted and saved as an attribute of a
data frame.
get_model(x, name = "model", element = NULL, ...)
x |
An object that contains a model object as an attribute. This could be a data frame or any other object that has an attribute containing the model. |
name |
The name of the attribute that contains the model object. Defaults
to |
element |
String or character vector. If provided, this argument allows you to specify which element(s) of the model object to return. This can be useful if the model object is a list or has multiple components, and you only want to extract a specific part. |
... |
Not used. |
The object that is stored as an attribute of x
with the name name
,
or the specific element of that object if element
is provided. If the
attribute or element does not exist, an error is raised.
# Example of using get_model
d <- data.frame(x = rnorm(100), y = rnorm(100))
# fit a model and save it as an attribute
model <- lm(y ~ x, data = d)
attr(d, "model") <- model
# get the model back
get_model(d)
# get the coefficients of the model
get_model(d, element = "coefficients")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.