Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

seqm

sequences, empty if "by" not conforming


Description

Generate sequences, but unlike "seq", return NULL, when "seq" would generate a backward sequence. This function is useful for for-loops, when empty loops are required in the case where by is in the "wrong" direction, see examples.

Usage

seqm(from, to, by=1)

Arguments

from

starting value of sequence.

to

(maximal) end value of the sequence.

by

increment of the sequence.

Value

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

Author(s)

Christian W. Hoffmann <christian@echoffmann.ch>

Examples

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

cwhmisc

Miscellaneous Functions for Math, Plotting, Printing, Statistics, Strings, and Tools

v6.6
GPL (>= 2)
Authors
Christian W. Hoffmann
Initial release
2018-08-24, 10:40:10

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.