从R语言对象中提取属性
我在R中拟合了一个GLM模型,在生成的模型对象中,有一个称为“terms”的元素。“terms”对象是“language”对象 我不熟悉“语言”对象。我想知道如何从model$terms对象中提取“attributes”。例如,如果我想从这个对象中获取“predvars”属性,我应该怎么做从R语言对象中提取属性,r,R,我在R中拟合了一个GLM模型,在生成的模型对象中,有一个称为“terms”的元素。“terms”对象是“language”对象 我不熟悉“语言”对象。我想知道如何从model$terms对象中提取“attributes”。例如,如果我想从这个对象中获取“predvars”属性,我应该怎么做 > model = glm(...) > typeof(model$terms) [1] "language" > model$terms losscost_bc_f
> 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"
>模型=glm(…)
>类型(型号$terms)
[1] “语言”
>范本$条款
losscost_bc_fire_cap~pol_year_fac+ded_group+ind_分数
属性(,“变量”)
列表(目标、油料年份、fac、ded组、ind分数)
......
属性(,“术语标签”)
[1] “pol_year_fac”“ded_bco_fire_group”“ind_grewscore”“cv_grewscore”
[5] “cv_log_tiv”
属性(,“订单”)
[1] 1 1 1 1 1
属性(,“截取”)
[1] 1
属性(,“响应”)
[1] 1
属性(,“.Environment”)
属性(,“预变量”)
清单(losscost_bc_fire_cap、pol_year_fac、ded_bco_fire_group、,
ind_grewscore、cv_grewscore、cv_log_tiv)
属性(,“数据类”)
losscost_bc_fire_cap pol_year_fac_bco_fire_group ind_grewscore
“数字”“因子”“因子”“因子”
cv_grewscore cv_log_tiv(重量)
“数字”“数字”“数字”
使用attr()
函数
attr(型号$terms,“predvars”)
或者(我认为)attributes(model$terms)$predvars
但是要注意:predvars
是一个未赋值的语言对象。如果您想使用它,您需要使用eval()
(或其他东西)。使用attr()
函数
attr(型号$terms,“predvars”)
或者(我认为)attributes(model$terms)$predvars
但是要注意:predvars
是一个未赋值的语言对象。如果您想使用它,您需要使用eval()
(或其他东西)