一旦使用 R 的
lm()
函数创建了线性回归模型,我想编写一段代码,它将 Estimate
向量从 coefficients
中排序,并列出最大的 5 个估计值,按降序对向量进行排序。我怎么能做这样的事?
# Assume that im using the `price` field to compare the other fields in the `data` data frame
model <- lm(price~., data=data)
values= summary(model)$coefficients
上面男女同校的
values
变量的当前输出如下所示:
你可以这样做:
library(tidyverse)
values %>%
as.data.frame() %>%
arrange(-Estimate)
如果你只想要一个估计向量,你可以用
pull(Estimate)
在管道中添加另一条线。