比方说,我的DF只有1列“类型” 在该类型中,有“恐怖”,“浪漫”,“小说”等。
类型
Horror
Horror
Romance
Fiction
Romance
如何编码,以便可以将“恐怖”对象组合为一个? 所以基本上,我希望表格显示
类型
Horror
Romance
Fiction
预先感谢
答案 0 :(得分:0)
unique(DF$Genre)
或
DF %>%
distinct(Genre)
答案 1 :(得分:0)
您可以使用aggregate
函数获取要查找的表。
## Your sample data
DF = read.table(text="Genre Score
Horror 4
Horror 6
Romance 7
Fiction 3
Romance 10",
header = TRUE)
TAB = aggregate(DF$Score, list(DF$Genre), mean)
names(TAB) = c("Genre", "MeanScore")
TAB
Genre MeanScore
1 Fiction 3.0
2 Horror 5.0
3 Romance 8.5