【发布时间】:2016-06-14 15:29:05
【问题描述】:
我需要在我的数据框中找到频率最低的扇区。使用 min 给出了最少的出现次数,但我想获得出现次数最少的相应扇区名称......所以在这种情况下,我希望它打印“消费订书钉”。我不断得到频率而不是实际的扇区名称。有没有办法做到这一点?
谢谢。
sector_count <- count(portfolio, "Sector")
sector_count
Sector freq
1 Consumer Discretionary 5
2 Consumer Staples 1
3 Health Care 2
4 Industrials 3
5 Information Technology 4
min(sector_count$freq)
[1] 1
【问题讨论】:
-
with(sector_count,Sector[which.min(freq)]) -
count不是基本 R 函数。本网站的标准做法是在此处的代码中使用此类函数之前包含library(dplyr)之类的行。 -
@BenBolker 谢谢,这也很有效。