Skip to content

expand.grip for permutations

4 messages · trekvana, R. Michael Weylandt, William Dunlap

#
if i were to have a block size of 4 people and i want to assign a treatment
combination to the entire block, there would be 16 different treatment
combinations (TTTT, TTTP, TTPP, PTTP, etc.)

i am trying to get all 16 permutations and i am able to use this code below.

drugs=c('P','T');
comb=expand.grid(drugs,drugs,drugs,drugs)

for a block size of 3 the code would be comb=expand.grid(drugs,drugs,drugs)
and for a block size of 2 it would be comb=expand.grid(drugs,drugs).

my question is whether there is a way to automatically create the comb
variable. i tried using expand.grid(rep(drugs, block.size) but that didn't
work.

any help on how i can proceed? thanks



--
View this message in context: http://r.789695.n4.nabble.com/expand-grip-for-permutations-tp4648067.html
Sent from the R help mailing list archive at Nabble.com.
#
On Wed, Oct 31, 2012 at 8:18 PM, trekvana <trekvana at aol.com> wrote:
do.call(expand.grid, rep(list(drugs),n))

where n is 3,4,5...

Cheers,
Michael
#
Instead of  
   rep(drugs, block.size)
use
   rep(list(drugs), block.size)
as the argument to expand.grid.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com