#==========================================================================================#
#==========================================================================================#
# This function returns all possible combinations. #
#------------------------------------------------------------------------------------------#
combn.boolean <<- function(x){
#----- Stop if x isn't a vector. -------------------------------------------------------#
if (! is.vector(x)) stop("x must be a vector")
#---------------------------------------------------------------------------------------#
#----- Get the length of vectors. ------------------------------------------------------#
nx = length(x)
#---------------------------------------------------------------------------------------#
#----- Build the list with all possible combinations (except all negative). ------------#
ans = mapply( FUN = combn
, m = sequence(nx)
, MoreArgs = list( x = sequence(nx)
, FUN = which.2.boolean
, along = x
, simplify = TRUE
)#end list
, SIMPLIFY = FALSE
)#end mapply
ans = lapply( X = ans, FUN = t)
#---------------------------------------------------------------------------------------#
#----- Concatenate all combinations to a matrix, and append the all FALSE case. --------#
ans = do.call("rbind",ans)
ans = rbind(rep(x=FALSE,times=nx),ans)
#---------------------------------------------------------------------------------------#
#----- Name the columns after the original x elements. ---------------------------------#
colnames(ans) = x
#---------------------------------------------------------------------------------------#
return(ans)
}#end combn.boolean
#==========================================================================================#
#==========================================================================================#
#==========================================================================================#
#==========================================================================================#
# This function converts indices into a Boolean. #
#------------------------------------------------------------------------------------------#
which.2.boolean <<- function(idx,along){
ans = rep(FALSE,times=length(along))
ans[idx] = TRUE
return(ans)
}#end which.2.sel
#==========================================================================================#
#==========================================================================================#
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.