【算法代码】
> x<-c(65,78,91,82,53,37,87)
> xcut<-cut(x,c(0,60,80,100))
> factor(xcut,label=c('A','B','C'))
[1] B B C C A A C
Levels: A B C
>
> tapply(x,xcut,FUN=mean)
(0,60] (60,80] (80,100]
45.00000 71.50000 86.66667
>
【算法代码】
> x<-c(65,78,91,82,53,37,87)
> xcut<-cut(x,c(0,60,80,100))
> factor(xcut,label=c('A','B','C'))
[1] B B C C A A C
Levels: A B C
>
> tapply(x,xcut,FUN=mean)
(0,60] (60,80] (80,100]
45.00000 71.50000 86.66667
>