Overview
A data transformation takes some data and returns new data. When the data takes the form of an array, the transformation is typically one of the following
- Map - transforms each record into a new record
- Aggregation - creates a single value as an aggregate of the array
The array map function takes an array of items, and returns a new array, with each item replaced by something new. It does this by taking a function as argument. This function takes an item and returns a new item.
As an example, consider the following code, which takes an array of numbers and creates a new array with each number doubled.
let list = [1,2,3,4,5];
let doubled = list.map(p=>2*p)
The following demonstrates various ways to use the map function to calculate different types of transformations.
- Single Record Maps - transforming each record in a dataset based on information in that record alone
- Adjacent Record Maps - transforming each record in a dataset based on information in that record and an adjacent record alone.
- Dataset Maps - transforms each record in the dataset using information from every record in the dataset.
- Running Total Maps - transforms each record based on the data in that record or data in any record prior to it in the dataset
Aggregations - creates a single value out of a list of values. Examples include sums and averages.
The following example demonstrates calculating a average using the $list function.
let data = [{value:1},{value:2},{value:3},{value:4},{value:5}];
let average = $list(data).map(p=>p.value).average();