制作一个表格,显示 R 中变量的 10 个最大值? [英] Make a table showing the 10 largest values of a variable in R?

查看:23
本文介绍了制作一个表格,显示 R 中变量的 10 个最大值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个简单的表格,展示数据集中给定变量的最大 10 个值,以及每个观察值的 4 个其他变量,因此基本上是我数据的一小部分.它看起来像这样:

I want to make a simple table that showcases the largest 10 values for a given variable in my dataset, as well as 4 other variables for each observation, so basically a small subset of my data. It would look something like this:

Score  District  Age  Group  Gender
17     B         23    Red   1
12     A         61    Red   0
11.7   A         18    Blue  0
10     B         18    Red   0
.
.
etc.

由此数据在 Score var 上排序.所有数据都包含在同一个数据帧中.

whereby the data is ordered on the Score var. All the data is contained within the same dataframe.

推荐答案

应该这样做...

data <- data[with(data,order(-Score)),]

data <- data[1:10,]

这篇关于制作一个表格,显示 R 中变量的 10 个最大值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆