seqm                 package:cwhmath                 R Documentation

_s_e_q_u_e_n_c_e_s, _e_m_p_t_y _i_f "_b_y" _n_o_t _c_o_n_f_o_r_m_i_n_g

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

     Generate sequences, but return NULL, when "seq" would generate an
     error.This function is useful for 'for'-loops, when empty loops
     are required, if 'by' is in the "wrong" direction, see _examples_.

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

       seqm(from, to, by=1)

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

    from: starting value of sequence.

      to: (maximal) end value of the sequence.

      by: increment of the sequence.

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

     'NULL', if (to-from)*by <0, otherwise usual result of 'seq' i.e.
     seq.default.

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

       seqm(12,4,-1)  #  12 11 10  9  8  7  6  5  4
       seqm(12,4,2)   #  NULL
       lo <- 1; up <- 3
       for (ii in lo:up) {
         cat(ii,"    ")
         for (kk in seqm(lo,ii-1)) {
           cat("   ",kk)  # do-in-lower-triangle
         }
         cat(" diag")     # do-something-on-the-diagonal
         for (kk in seqm(ii+1,up)) {
           cat("  :",kk)  # do-in-upper-traingle
         }
         cat("\n")    
       }
     # 1      diag  : 2  : 3
     # 2         1 diag  : 3
     # 3         1    2 diag

