combinations             package:gtools             R Documentation

_E_n_u_m_e_r_a_t_e _t_h_e _C_o_m_b_i_n_a_t_i_o_n_s _o_r _P_e_r_m_u_t_a_t_i_o_n_s _o_f _t_h_e _E_l_e_m_e_n_t_s _o_f _a _V_e_c_t_o_r

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

     'combinations' enumerates the possible combinations of a specified
     size from the elements of a vector.  'permutations' enumerates the
     possible permutations.

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

     combinations(n, r, v=1:n, set=TRUE, repeats.allowed=FALSE)
     permutations(n, r, v=1:n, set=TRUE, repeats.allowed=FALSE)

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

       n: Size of the source vector 

       r: Size of the target vectors 

       v: Source vector. Defaults to '1:n'

     set: Logical flag indicating whether duplicates should be removed
          from the source vector 'v'. Defaults to 'TRUE'.

repeats.allowed: Logical flag indicating whether the constructed
          vectors nay include duplicated values.  Defaults to 'FALSE'.  

_D_e_t_a_i_l_s:

     Caution: The number of combinations and permutations increases
     rapidly with 'n' and 'r'!.

     To use values of 'n' above about 45, you will need to increase R's
     recursion limit.  See the 'expression' argument to the 'options'
     command for details on how to do this.

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

     Returns a matrix where each row contains a vector of length 'n'.

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

     Original versions by Bill Venables Bill.Venables@cmis.csiro.au. 
     Extended to handle 'repeats.allowed' by Gregory R. Warnes
     gregory.r.warnes@pfizer.com.

_R_e_f_e_r_e_n_c_e_s:

     Venables, Bill.  "Programmers Note", R-News, Vol 1/1, Jan. 2001.
     <URL: http://cran.r-project.org/doc/Rnews>

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

     'choose', 'options'

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

     combinations(3,2,letters[1:3])
     combinations(3,2,letters[1:3],repeats=TRUE)

     permutations(3,2,letters[1:3])
     permutations(3,2,letters[1:3],repeats=TRUE)

     # To use large 'n', you need to change the default recusion limit
     options(expressions=1e5)
     cmat <- combinations(300,2)
     dim(cmat) # 44850 by 2 

