Aaa <- data.frame(amount=c(1,2,1,2,1,1,2,2,1,1,1,2,2,2,1),
card=c("a","b","c","a","c","b","a","c","b","a","b","c","a","c","a"))
aggregate(x=Aaa$amount, by=list(Aaa$card), FUN=mean)
## Group.1 x
## 1 a 1.50
## 2 b 1.25
## 3 c 1.60
tapply(Aaa$amount, Aaa$card, mean)
## a b c
## 1.50 1.25 1.60
上面是一个示例代码。
看起来aggregate
两者tapply
都非常方便并且执行类似的功能。
有人可以解释或举例说明他们的差异吗?