combs                package:caTools                R Documentation

_A_l_l _C_o_m_b_i_n_a_t_i_o_n_s _o_f _k _E_l_e_m_e_n_t_s _f_r_o_m _V_e_c_t_o_r _v

_D_e_s_c_r_i_p_t_i_o_n:

     Finds all unordered combinations of 'k' elements from vector  'v'.

_U_s_a_g_e:

     combs(v,k)

_A_r_g_u_m_e_n_t_s:

       v: Any numeric vector

       k: Number of elements to choose from vector 'v'. Integer smaller
           or equal than length of 'v'.  

_V_a_l_u_e:

     'combs(v,k)' (where 'v' has length 'n') creates a matrix with 
     n!/((n-k)! k!) ('n' choose 'k') rows and 'k' columns containing
     all possible combinations of 'n' elements  taken 'k' at a time.

_A_u_t_h_o_r(_s):

     Jarek Tuszynski (SAIC) jaroslaw.w.tuszynski@saic.com

_S_e_e _A_l_s_o:

     I discovered recently that R packages already have two functions
     with  similar capabilities: 'combinations' from 'gTools' package
     and 'nchoosek' from 'vsn' package. Also similar to Matlab's
     'nchoosek' function (<URL: 
     http://www.mathworks.com/access/helpdesk/help/techdoc/ref/nchoosek.html>)

_E_x_a_m_p_l_e_s:

       combs(2:5, 3) # display examples
       combs(c("cats", "dogs", "mice"), 2)
       
       a = combs(1:4, 2)
       b = matrix( c(1,1,1,2,2,3,2,3,4,3,4,4), 6, 2)
       stopifnot(a==b)

