我有一个数据框如下:
mydf <- data.frame(Term = c('dog','cat','lion','tiger','pigeon','vulture'), Category = c('pet','pet','wild','wild','pet','wild'),
Count = c(12,14,19,7,11,10), Rate = c(0.4,0.7,0.3,0.6,0.1,0.8), Brand = c('GS','GS','MN','MN','PG','MN') )
产生数据框:
Term Category Count Rate Brand
1 dog pet 12 0.4 GS
2 cat pet 14 0.7 GS
3 lion wild 19 0.3 MN
4 tiger wild 7 0.6 MN
5 pigeon pet 11 0.1 PG
6 vulture wild 10 0.8 MN
我希望将此数据框转换为以下resultDF
Category pet wild
Term dog,cat,pigeon lion,tiger,vulture
Countlessthan13 dog,pigeon tiger,vulture
Ratemorethan0.5 cat tiger,vulture
Brand GS,PG MN
行标题表示类似 Countlessthan13 的操作意味着 Count < 13 应用于术语然后进行分组。另请注意,品牌名称是独一无二的,不会重复。
我已经尝试过 dcast 和 melt ......但没有得到想要的结果。