Aggregate
New to Analytica 4.2
Aggregate( X,map : Array[I] ; I, targetIndex : Index )
Aggregate converts an array «X» indexed by a fine-grained index «I» (e.g., Months) into an array indexed by a coarser index «targetIndex» (e.g., Years), by aggregating all the elements that map to the same «targetIndex» value. The «map» parameter specifies how the elements of «I» map to the elements of «targetIndex». Each cell of «map» should be an element of «targetIndex» (or, if you also specify an optional positional:true parameter, then each element of «map» can specify an integer position along «targetIndex»).
In its standard usage, Aggregate sums all elements from «X» that map to the same element along «targetIndex». However, the type of aggregation can be changed using an optional «type» parameter, containing the name of or handle to any valid aggregation function, such as Max, Min, Product, Average or Median.
Library
Array functions
Examples
Index Months := Sequence(MakeDate(2009,1,1),MakeDate(2020,1,1),dateUnit:"M") Index Years := 2009..2020 MonthsToYears := DatePart(Months,"Y") Revenue_by_month := { array indexed by Months } Revenue_by_year := Aggregate(Revenue_by_month,MonthsToYears,Months,Years)
Custom Aggregation types
Positional Maps
Default Value
Inverses of Aggregate
See Also
- Subscript-Slice Operator -- standard reindexing
- Frequency -- basically aggregation with "count" type
Enable comment auto-refresher