如何创建垂直排列的值频率组合表,
> df = data.frame(fruit=c("apple", "banana", "cherry", "cherry", "apple", "banana", "apple", "date"));
> table(df$fruit)
apple banana cherry date
3 2 2 1
到目前为止,一切都很好。但我想要这样的东西(例如,基于频率的基本操作和值的子集):
Fruit Freq
"apple" 3
"banana" 2
"cherry" 2
"date" 1
在 SQL 中,这将是SELECT fruit, COUNT(*) AS Freq FROM df GROUP BY fruit
,并且会产生一个类似于此问题起点的表: https ://stats.stackexchange.com/questions/15574/how-to-convert-a-frequency-table-into-值向量
在R中是否有一种简单的方法可以做到这一点?(或者,这是否表明思维方式过于“SQL”而“R”不够?)