#对向量的子集进行操作
#tapply(参数):tapply(向量,因子/因子列表,函数/函数名)
> x <- c(rnorm(5),runif(5),rnorm(5,1))
> f <- gl(3,5)
> f
[1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
Levels: 1 2 3
> tapply(x,f,mean)
1 2 3
-0.5004154 0.4044779 0.9769996
> tapply(x,f,mean,simplify = FALSE)
$`1`
[1] -0.5004154
$`2`
[1] 0.4044779
$`3`
[1] 0.9769996
> tapply(x,f,sum)
1 2 3
-2.502077 2.022389 4.884998
转载于:https://www.cnblogs.com/hankleo/p/9942325.html