如何在线性回归函数中仅引用数字



在r中,假设我有这个:house_model是线性回归模型

b_0 = house_model$coefficients[1]
b_1 = house_model$coefficients[2]
print(b_0)
print(b_1)

这将输出

(Intercept) 
-1.171116 
area
0.17545795

所以我只想得到数字而不是名字。我只想看到 -1.171116 和 .17545795。有没有办法做到这一点?

print(unname(b0))

cat(b0,"n")

("n"是添加一个换行符; cat()也跳过了行首的[1](

您可以按如下方式使用 as.numeric 函数:

# without an additional variable
print(as.numeric(house_model$coefficients[1]))
# with an additional variable
print(as.numeric(b_0))

最新更新