[英]Extract attributes from language object in R
I fit a GLM model in R, and in the resulting model object, there is an element that is called 'terms'.我在 R 中安装了 GLM model,并在生成的 model ZA8CFDE6331BD59EB62AC96F8911 中安装了一个名为 4B662AC96F8911 的元素。 The 'terms' object is an 'language' object.
“术语”object 是“语言”object。
I am not familiar with the 'language' object.我不熟悉“语言”object。 I am wondering how I would be able to extract the 'attributes' from the model$terms object.
我想知道如何从模型$terms object 中提取“属性”。 For example, if I would like to get the 'predvars' attributes from this object, how should I do it?
例如,如果我想从这个 object 中获取 'predvars' 属性,我应该怎么做?
> model = glm(...)
> typeof(model$terms)
[1] "language"
> model$terms
losscost_bc_fire_cap ~ pol_year_fac + ded_group + ind_score
attr(,"variables")
list(target, pol_year_fac, ded_group , ind_score)
......
attr(,"term.labels")
[1] "pol_year_fac" "ded_bco_fire_group" "ind_grewscore" "cv_grewscore"
[5] "cv_log_tiv"
attr(,"order")
[1] 1 1 1 1 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
attr(,"predvars")
list(losscost_bc_fire_cap, pol_year_fac, ded_bco_fire_group,
ind_grewscore, cv_grewscore, cv_log_tiv)
attr(,"dataClasses")
losscost_bc_fire_cap pol_year_fac ded_bco_fire_group ind_grewscore
"numeric" "factor" "factor" "factor"
cv_grewscore cv_log_tiv (weights)
"numeric" "numeric" "numeric"
Use the attr()
function.使用
attr()
function。
attr(model$terms, "predvars")
Or (I think) attributes(model$terms)$predvars
或者(我认为)
attributes(model$terms)$predvars
Watch out, though: the predvars
is an unevaluated language object.但请注意:
predvars
是一种未经评估的语言object 。 You'll need to use eval()
(or something) if you want to work with it.如果你想使用它,你需要使用
eval()
(或其他东西)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.