User:Karenlee

Revision as of 22:13, 13 August 2015 by Karenlee (talk | contribs)

Categoty:Array Library

Sequence(start, end, step, strict, dateUnit)

Creates a list of numbers increasing or decreasing from start to end by increments (or decrements) of step, which is optional and defaults to 1. When the strict parameter is omitted or false, 'step' must be a positive number and the sequence will decrement by step when end is less than start, guaranteeing at least one element. When strict is specified as true, a positive step increments and negative step returns a decrementing sequence, possibly with zero elements if end would come before start.

The optional dateUnit parameter is used when creating a sequence of dates, with increments in units of Years (dateUnit:'Y'), Months ('M'), Days ('D' or omitted), Weekdays ('WD'), Hours ('h'), minutes ('m') or seconds ('s').

All parameters must be deterministic scalar numbers, not arrays.

You can also select this function using the Sequence option from the expr menu.

The expression m .. n using the operator ".." is equivalent to Sequence(m, n, 1).

Strict sequences

Sequence expects the «step» to be positive (or omitted, in which case a step of 1 is assumed). A decreasing sequence is obtained by specifying a 'start less than ‘’’’’end’’’’’. As a result of this convention, a sequence will always have at least one element.

There are cases where a strict sequence is desired, such that the sequence proceeds from start in increments of step, according to the sign of step. When step proceeds in the direction away from ‘’’’’end’’’’’, then a zero-length sequence results. For example, in a For..Do loop, you may want zero iterations when «end» is less than start. A strict sequence is obtained by specifying the optional parameter «strict» as true, e.g.

Sequence(x1,x2,strict:true)

When «strict» is specified as true, the «step» may be negative, and must be negative to obtain a decreasing sequence.

Date Sequences

You can use Sequence to generate a sequence of dates between a given start and stop date, in increments such as months and years, by specifying the optional ‘’’’’dateUnit’’’’’ parameter. Possible date units include: "Y" (years), "Q" (quarters), "M" (months), "WD" (weekdays), "D" (days), "h" (hours), "m" (minutes), "s" (seconds).

Sequence( MakeDate(2009,1,1), MakeDate(2010,12,31), 4, dateUnit:"M" ) →
  [ 1-Jan-2009, 1-May-2009, 1-Sep-2009, 1-Jan-2010, 1-May-2010, 1-Sep-2010 ]

Character Sequences

The start and «stop» characters may be single characters. In this case, a sequence of characters following ASCII order is returned.

Sequence('T','f') → ['T','U','V','W','X','Y','Z','[','\',']','^','_','`','a','b','c','d','e','f']
Sequence('!','@') → ['!','""','#','$','%','&',,'(',')','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@']

Spreadsheet Column Name Sequences

When start and ‘’’’’end’’’’’ are multi-letter sequences, containing only letters, with all letters having the same upper-case or lower-case, then a spreadsheet column sequence is returned.

These sequences are letter sequences that go from 'A'..'Z', then from 'AA'..'AZ', 'BA'..'BZ', ... 'ZA'..'ZZ', then 'AAA'..'ZZZ', 'AAAA'..'ZZZZ', etc., up to six digits total.

Sequence('W','AF') → ['W','X','Y','Z','AA','AB','AC','AD','AE','AF']

For these sequences, the start and stop must consist entirely of letters, and all letters must be all upper case or all lower case.

Examples

If end is greater than start, the sequence is increasing:

Sequence(1,5) →
List View Expression View
IMAGE of List View [1,2,3,4,5]

If start is greater than end, the sequence is decreasing:

Sequence(5,1) → [5, 4, 3, 2, 1]

Unless strict is true:

Sequence(5, 1, strict:true) → []
Sequence(5, 1, -2, strict:true)  → [5, 3, 1]

If start and end are not integers, and you omit stepSize, it rounds them:

Sequence(1.2, 4.8) → [1, 2, 3, 4, 5]

If you specify stepSize, it can create non-integer values:

Sequence(0.5, 2.5, 0.5) → [0.5, 1, 1.5, 2, 2.5]

History

  • Analytica 4.4 or patch 4.3.3
    • Spreadsheet column name sequences
    • Character sequences
  • Analytica 4.2
    • Strict sequences
    • Date sequences

Table Test Formatting

On the Left

MDTable(T,Rows,Cols,[Car_type,Mpg],'average','n/a')
Mpg ▶
Car_type 26 30 35
VW 2185 1705 n/a
Honda 2330 n/a 2210
BMW n/a 2955 2835

On Top

MDTable(T,Rows,Cols,[Car_type,Mpg],'average','n/a')

Mpg ▶
Car_type ▼ 26 30 35
VW 2185 1705 | n/a
Honda 2330 n/a 2210
BMW n/a 2955 2835

MH Test

MDTable(T,Rows,Cols,[Car_type,Mpg],'average','n/a')

Mpg ▶
Car_type 26| 30|35|- VW 2185 1705 n/a
Honda 2330 n/a 2210
BMW n/a 2955 2835