Transforming functions
A transforming function operates across a dimension of an array and returns a result that has the same dimensions as its input array.
The function Cumulate(x, i) illustrates some properties of transforming functions.
Example:
Cumulate(Car_prices,Years) →
Years ▶ | |||||
---|---|---|---|---|---|
Car_type ▼ | 2005 | 2006 | 2007 | 2008 | 2009 |
VW | 16K | 33K | 51K | 70K | 90K |
Honda | 18K | 37K | 57K | 79K | 103K |
BMW | 25K | 51K | 79K | 109K | 141K |
The second parameter, i, specifying the dimension over which to cumulate, is optional. But if the array, x, has more than one dimension, Analytica might not cumulate over the dimension you expect. For this reason, it is safer always to specify the dimension index explicitly in any transforming function.
Cumulate(x, i, passNull, reset)
Returns an array with each element being the sum of all of the elements of x along dimension i up to, and including, the corresponding element of x.
Cumulate(1, i)
is equivalent to @i
, where each numbers the elements of an index.
The optional passNull parameter controls now null
values in x are passed through to the result.If passNull is false or omitted, then null values in x are ignored and do not effect the cumulation. Leading null
values will be passed through, but after a numeric value is encountered, null
values in x will cumulate the same as zero.
The optional reset parameter, an array of boolean values along i, can be used to indicate points along i where you want to restart the cumulation. For example, if you want to restart the cumulation following a state change, reset can be set to true each time a new state is entered.
Library: Array
Example:
Cumulate(Cost_of_ownership, Time) →
Years ▶ | |||||
---|---|---|---|---|---|
Car_type ▼ | 0 | 1 | 2 | 3 | 4 |
VW | 2810 | 5761 | 8859 | 12.11K | 15.53K |
Honda | 3535 | 7382 | 11.28K | 15.45K | 19.81K |
BMW | 3185 | 6479 | 9888 | 13.42K | 17.07K |
Cumulate(Cost_of_ownership,Car_type, reset:Time=2) →
Years ▶ | |||||
---|---|---|---|---|---|
Car_type ▼ | 0 | 1 | 2 | 3 | 4 |
VW | 2810 | 5761 | 3098 | 6351K | 9767K |
Honda | 3535 | 7382 | 3897K | 8063K | 12.43K |
BMW | 3185 | 6479 | 3409 | 6938K | 10.59K |
See Array Function Example Variables for example array variables used here and below.
Enable comment auto-refresher