我需要在数据框中找到频率最低的扇区。使用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
你要
sector_count$Sector[which.min(sector_count$freq)]
该which.min(sector_count$freq)
函数选择找到最小值的索引或行。然后,sector_count $ Sector向量是相应值的子集。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句