[R] breaking up n object into random groups

Bert Gunter gunter.berton at gene.com
Fri Dec 2 16:28:15 CET 2011


There are a million ways to do this, probably.

brks <- c(1,sort(sample(seq_len(99),3)),100)  ##  4 random groups

and then use brks as the breaks parameter in cut() with include.lowest = TRUE

?cut

-- Bert

On Fri, Dec 2, 2011 at 7:09 AM, statfan <irene_vrbik at hotmail.com> wrote:
> say n = 100
> I want to partition this into 4 random groups wheren n1 + n2 + n3 + n4 = n
> and ni is the number of elements in group i.
>
> Thank you for you help
>
> --
> View this message in context: http://r.789695.n4.nabble.com/breaking-up-n-object-into-random-groups-tp4147476p4147476.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list