[R] grouping
Giovanni Petris
gpetris at uark.edu
Tue Apr 3 15:13:56 CEST 2012
Probably something along the following lines:
> x <- c( 46, 125 , 36 ,193, 209, 78, 66, 242 , 297 , 45)
> sorted <- c(36 , 45 , 46, 66, 78, 125,193, 209, 242, 297)
> tapply(sorted, INDEX = (seq_along(sorted) - 1) %/% 3, FUN = mean)
0 1 2 3
42.33333 89.66667 214.66667 297.00000
Hope this helps,
Giovanni
On Tue, 2012-04-03 at 08:47 -0400, Val wrote:
> Hi all,
>
> Assume that I have the following 10 data points.
> x=c( 46, 125 , 36 ,193, 209, 78, 66, 242 , 297 , 45)
>
> sort x and get the following
> y= (36 , 45 , 46, 66, 78, 125,193, 209, 242, 297)
>
> I want to group the sorted data point (y) into equal number of
> observation per group. In this case there will be three groups. The first
> two groups will have three observation and the third will have four
> observations
>
> group 1 = 34, 45, 46
> group 2 = 66, 78, 125
> group 3 = 193, 209, 242,297
>
> Finally I want to calculate the group mean
>
> group 1 = 42
> group 2 = 87
> group 3 = 234
>
> Can anyone help me out?
>
> In SAS I used to do it using proc rank.
>
> thanks in advance
>
> Val
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Giovanni Petris <GPetris at uark.edu>
Associate Professor
Department of Mathematical Sciences
University of Arkansas - Fayetteville, AR 72701
Ph: (479) 575-6324, 575-8630 (fax)
http://definetti.uark.edu/~gpetris/
More information about the R-help
mailing list