r - 如何检索数据框中存在的列中重复次数最多的值

标签 r dataframe max

我正在尝试检索数据框中特定列中重复次数最多的值。以下是我的示例数据和代码。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

根据我的示例数据,我需要返回最重复的类别,即保险。
subset(subset(Forbes2000,country=="Bermuda")

最佳答案

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

关于r - 如何检索数据框中存在的列中重复次数最多的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12187187/

相关文章:

python - DateOffset Pandas 减法

r - 在 R 中的另一个 data.frame 中按权重乘以每列的值

比较两个字符串时,Python max() 函数无法给出正确的结果

r - 查找一组中的至少一个元素是否与至少一个模式匹配

python - 在python中重新排列数据框

r - 将函数参数传递给 dplyr select

python - 我试图在一个句子中找到最大长度的单词

c++ - opencv cv::max 行为意外

r - 如何在 ggplot2 的条形图上正确地将 geom_errorbar 设置为 "dodge"?

r - 跨多个列的 Pivot_wider