从表中切出一个原子向量并在 R 中按降序排序

问题描述 投票:0回答:1

一旦使用 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
变量的当前输出如下所示:

r dataframe format linear-regression lm
1个回答
0
投票

你可以这样做:

library(tidyverse)
values %>%
  as.data.frame() %>%
  arrange(-Estimate)

如果你只想要一个估计向量,你可以用

pull(Estimate)
在管道中添加另一条线。

© www.soinside.com 2019 - 2024. All rights reserved.