Difference between revisions of "Sequence"
Line 1: | Line 1: | ||
[[Category:Functions that create lists]] | [[Category:Functions that create lists]] | ||
+ | [[Category:Array Library]] | ||
[[Category:Doc Status C]] <!-- For Lumina use, do not change --> | [[Category:Doc Status C]] <!-- For Lumina use, do not change --> | ||
− | = Sequence( | + | == Sequence(start, end, ''step'') == |
+ | Creates a list of numbers increasing or decreasing from «start» to «end» by increments (or decrements) of «step». «step» is optional and must be a positive number; if it is omitted, Analytica uses increments of 1. «start», «end», and «step» must be deterministic scalar numbers, not arrays. See [[Expressions that don't array-abstract]]. | ||
− | + | You can also select this function using the '''Sequence''' option from the '''expr''' menu. | |
− | + | The expression <code>m .. n</code> using the operator <tt>".."</tt> is equivalent to <code>Sequence(m, n, 1)</code>. | |
− | + | ==Examples== | |
− | = Examples = | + | If «end» is greater than «start», the sequence is increasing: |
+ | Sequence(1, 5) → [1, 2, 3, 4, 5] | ||
− | + | If «start» is greater than «end», the sequence is decreasing: | |
+ | Sequence(5,1) → [5, 4, 3, 2, 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] | ||
− | + | == Optional parameters == | |
+ | === Strict === | ||
+ | Normally, if «start» is larger than «end», and «step» is positive, the sequence decrements by «step». 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|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». Specifying the optional parameter «strict» as true obtains a strict Sequence, for example: | |
+ | 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. For example: | |
+ | Sequence(5, 1, strict: True) → [] | ||
+ | Sequence(5, 1, -2, strict: True) → [5, 3, 1] | ||
− | + | === DateUnit === | |
+ | If you want to create a sequence of dates or times, successive days or hours, the first day of each week, month, or year, and so on, you can set the optional «dateUnit» parameter to the relevant date/time character. For example: | ||
+ | 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] | ||
− | + | These are the characters defining each date and time unit: | |
+ | * Years (<tt>dateUnit: 'Y'</tt>) | ||
+ | * Months (<tt>'M'</tt>) | ||
+ | * Days (<tt>'D'</tt> this is the default if «dateUnit» is omitted) | ||
+ | * Weekdays (<tt>'WD'</tt>) | ||
+ | * Hours (<tt>'h'</tt>) | ||
+ | * Minutes (<tt>'m'</tt>) | ||
+ | * Seconds (<tt>'s'</tt>). | ||
− | + | ==Character Sequences== | |
− | + | The «start» and «end» 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('!', '@') → |
+ | ['!', '""', '#', '$', '%', '&', '<nowiki>'</nowiki>', '(', ')', '*', '+', ',', '-', '.', '/', '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. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | = Spreadsheet Column Name Sequences = | ||
− | |||
− | |||
− | |||
− | When «start» and | ||
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. | 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 «end» must consist entirely of letters, and all letters must be all upper case or all lower case. | |
− | + | ==History== | |
− | + | *Analytica 4.4 or patch 4.3.3 | |
− | + | **Spreadsheet column name sequences | |
− | = | + | **Character sequences |
− | + | *Analytica 4.2 | |
− | + | **Strict sequences | |
− | + | **Date sequences | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Revision as of 19:52, 20 August 2015
Sequence(start, end, step)
Creates a list of numbers increasing or decreasing from «start» to «end» by increments (or decrements) of «step». «step» is optional and must be a positive number; if it is omitted, Analytica uses increments of 1. «start», «end», and «step» must be deterministic scalar numbers, not arrays. See Expressions that don't array-abstract.
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)
.
Examples
If «end» is greater than «start», the sequence is increasing:
Sequence(1, 5) → [1, 2, 3, 4, 5]
If «start» is greater than «end», the sequence is decreasing:
Sequence(5,1) → [5, 4, 3, 2, 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]
Optional parameters
Strict
Normally, if «start» is larger than «end», and «step» is positive, the sequence decrements by «step». 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». Specifying the optional parameter «strict» as true obtains a strict Sequence, for example:
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. For example:
Sequence(5, 1, strict: True) → [] Sequence(5, 1, -2, strict: True) → [5, 3, 1]
DateUnit
If you want to create a sequence of dates or times, successive days or hours, the first day of each week, month, or year, and so on, you can set the optional «dateUnit» parameter to the relevant date/time character. For example:
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]
These are the characters defining each date and time unit:
- Years (dateUnit: 'Y')
- Months ('M')
- Days ('D' this is the default if «dateUnit» is omitted)
- Weekdays ('WD')
- Hours ('h')
- Minutes ('m')
- Seconds ('s').
Character Sequences
The «start» and «end» 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 «end» must consist entirely of letters, and all letters must be all upper case or all lower case.
History
- Analytica 4.4 or patch 4.3.3
- Spreadsheet column name sequences
- Character sequences
- Analytica 4.2
- Strict sequences
- Date sequences
Enable comment auto-refresher