gen01pat {lazy.tools} | R Documentation |
Generate all possible 0-1 patterns of given length, or binary partition index matrix
gen01pat(nitems, sort = 0, partition = 0, print = 0)
nitems |
The length of the pattern |
sort |
= 1 to sort the result from the left |
partition |
= 1 to generate binary partition index matrix |
print |
= 1 to print the result |
Schatzoff et al method is used.
nitems must be less than log(.Machine$integer.max)/log(2).
Essentially the same as
cprod( rep(list(0:1),nitems) )
but gen01pat is much faster.
2^nitems x nitems
matrix \
or when partition=1
is given \
2^{nitems-1}-1 x nitems
matrix
Schatzoff, M., Tsao, R. and Fienberg, S. (1968) Efficient Calculation of All Possible Regressions. Technometrics. Vol. 10, No. 4, pp. 769-779
gen01pat( 4 )
gen01pat( 4, partition=1, sort=-2 )
pindex=gen01pat( 4, partition=1 )
left=apply(pindex,1,function(x) letters[1:4][as.logical(x)])
right=lapply(left,function(x){setdiff(letters[1:4],x)})
res=mapply( function(x,y){list(left=x,right=y)}, left,right, SIMPLIFY=FALSE)
Print(res)