[R] Odp: Grouping

From: Petr PIKAL <petr.pikal_at_precheza.cz>
Date: Fri, 25 Jan 2008 13:48:08 +0100


Hi

r-help-bounces_at_r-project.org napsal dne 24.01.2008 23:21:05:

> I need to group some subjects according to two
> variables (var1, var2)
>
> I have a data frame that looks something like this:
>
> Subject var1 var2
> 1 400 150
> 2 320 100
> 3 580 600
> 4 145 789
>
>
> Each suject would fall into one of 2 categories ('A'
> or 'B'). I want to find (and see) all the possible
> combinations of letter assignment that exist, but
> every combination needs to have an equal amount of
> subjects categorized as 'A' or 'B'(eg. if I have 20
> subjects there should be 10 assigned with letter 'A'
> and 10 with letter 'B')
>
> Thank you in advance for any hints,

The best hint seems to be trying to post some code which will explain more clearly what you want to achieve. You want to split your data to two groups according to the value of var1 and var2 and in the same time to keep both groups the same size? It seems to me rather contradictive.

If you want to sample your data without replacement into 2 groups with same number of members just sample a vector of indices

sel<-sample(1:20, 10)
x<-1:20

x[sel]
 [1] 20  3 13 12 14  7 11  1  5  2
x[-sel]
 [1]  4  6  8  9 10 15 16 17 18 19

Regards
Petr

>
> Judith
>
>
>
>



> Never miss a thing. Make Yahoo your home page.
>
> ______________________________________________
> 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.


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. Received on Fri 25 Jan 2008 - 12:50:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 25 Jan 2008 - 13:30:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive