Re: [R] Splitting a vector into equal groups

2009-05-05 Thread Uwe Ligges
utkarshsinghal wrote: Hi All, I have vector of length 52, say, x=sample(30,52,replace=T). I want to sort x and split into five *nearly equal groups*. Note that the observations are repeated in x so in case of a tie I want both the observations to fall in same group. This seems a very common

Re: [R] Splitting a vector into equal groups

2009-05-04 Thread Berwin A Turlach
G'day Utkarsh, On Mon, 04 May 2009 11:51:21 +0530 utkarshsinghal wrote: > I have vector of length 52, say, x=sample(30,52,replace=T). I want to > sort x and split into five *nearly equal groups*. What do you mean by *nearly equal groups*? The size of the groups should be nearly equal? The sum

Re: [R] Splitting a vector into equal groups

2009-05-04 Thread Dimitris Rizopoulos
check functions cut() and quantile(), and cut2() from package Hmisc; maybe the following is close to what you want: x <- sample(30, 52, replace = TRUE) k <- 5 # how many groups qs <- quantile(x, seq(0, 1, length.out = k + 1)) y <- cut(x, round(qs), include.lowest = TRUE) y table(y) I hope it

Re: [R] Splitting a vector into equal groups

2009-05-04 Thread ronggui
lattice:::equal.count may be what you want. 2009/5/4 utkarshsinghal : > Hi All, > > I have vector of length 52, say, x=sample(30,52,replace=T). I want to > sort x and split into five *nearly equal groups*. Note that the > observations are repeated in x so in case of a tie I want both the > observa

[R] Splitting a vector into equal groups

2009-05-03 Thread utkarshsinghal
Hi All, I have vector of length 52, say, x=sample(30,52,replace=T). I want to sort x and split into five *nearly equal groups*. Note that the observations are repeated in x so in case of a tie I want both the observations to fall in same group. This seems a very common task to do, but still I c