如何检索数据框中存在的列中最重复的值 [英] How to retrieve the most repeated value in a column present in a data frame

查看:137
本文介绍了如何检索数据框中存在的列中最重复的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在检索数据框中存在的特定列中最重复的值。以下是我的示例数据和代码.A

I am trying to retrieve the most repeated value in a particular column present in a data frame.Here is my sample data and code below.A

data("Forbes2000", package = "HSAUR")
head(Forbes2000)


  rank                name        country             category  sales profits  assets marketvalue
1    1           Citigroup  United States              Banking  94.71   17.85 1264.03      255.30
2    2    General Electric  United States        Conglomerates 134.19   15.59  626.93      328.54
3    3 American Intl Group  United States            Insurance  76.66    6.46  647.66      194.87
4    4          ExxonMobil  United States Oil & gas operations 222.88   20.96  166.99      277.02
5    5                  BP United Kingdom Oil & gas operations 232.57   10.27  177.57      173.54
6    6     Bank of America  United States              Banking  49.01   10.81  736.45      117.55

根据我的样本数据,我需要返回最重要的保险类别。

As per my sample data I need to return the most repeated category which is Insurance.

subset(subset(Forbes2000,country=="Bermuda")


推荐答案

tail(names(sort(table(Forbes2000$category))), 1)

这篇关于如何检索数据框中存在的列中最重复的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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