R 如何从步骤()获得变量名的结果列表?
我正在使用r中的step()函数。步骤()得出的变量列表应该保存在模型中的方法是什么?假设我有一个带有响应向量和几个预测器X、Y和Z的数据帧。Step()得出结论,最终模型中只应包含X和Y。如何获得向量R 如何从步骤()获得变量名的结果列表?,r,R,我正在使用r中的step()函数。步骤()得出的变量列表应该保存在模型中的方法是什么?假设我有一个带有响应向量和几个预测器X、Y和Z的数据帧。Step()得出结论,最终模型中只应包含X和Y。如何获得向量c('X','Y') -- 作为对第一个答案的回应,我尝试了$coverties和names()。两者都不起作用 这里是打印(“名称”)的输出;打印(名称(df_lm_2$系数)) [1] "(Intercept)" "How.often2"
c('X','Y')
--
作为对第一个答案的回应,我尝试了$coverties和names()。两者都不起作用
这里是打印(“名称”)的输出;打印(名称(df_lm_2$系数))
[1] "(Intercept)" "How.often2" "How.often5"
[4] "How.often6" "How.often7" "How.often8"
[7] "Bathroom.s.2" "Bathroom.s.3" "Bathroom.s.5"
[10] "Bathroom.s.7" "Other.details..option.2.TRUE" "description_length"
[13] "has_descriptionTrue" "Other.details..option.6.TRUE" "Bedroom.s.2"
[16] "Bedroom.s.3" "Bedroom.s.4" "Bedroom.s.5"
[19] "Bedroom.s.6" "weekend1" "Other.details..option.7.TRUE"
[22] "Other.details..option.3.TRUE"
我最终想要的只是重要的列名,而不是每个因素的级别。对于上下文,以下是列名:
[1] "=------Colnames--------"
[1] "Bathroom.s." "Bedroom.s." "bid_price" "description_length"
[5] "has_description" "hour_of_day" "How.often" "log_bid_price"
[9] "month" "Other.details..option.1." "Other.details..option.2." "Other.details..option.3."
[13] "Other.details..option.4." "Other.details..option.5." "Other.details..option.6." "Other.details..option.7."
[17] "req_source" "Square.feet" "Type.of.home" "weekend"
根据
的帮助页面中的示例执行步骤
lm1 <- lm(Fertility ~ ., data = swiss)
slm1 <- step(lm1)
查看名称(slm1)
了解更多信息
names(slm1$coefficients)