Using a functional map to reorder data
Use a functional map to arrange data in a different order. For example, you are growing some flowers and tracking their progress. You have some data for the measurements you took: height, number of leaves, water intake, and so on. These ProgressReadings are in no particular order in your input data. For example, the readings for daisy are scattered throughout the input data.
Shown below is some input data:
Apr-06,Alstromeria,24.14,15,7,32.5
Mar-20,Daisy,15.3,13,12,3.67
May-02,Lily,10.4,7,13,2.5
Apr-22,Daisy,22.4,8,12,2.6
Mar-09,Snapdragon,10.2,7,10,3.2
May-11,Alstromeria,26.8,18,11,3.12
Apr-06,Iris,5.89,5,6,2.7
Apr-10,Daisy,18.4,8,13,4.1
You want to generate an output that consists of reports, one for each flower type. You want a report for alstromeria, one for daisies, one for snapdragons, and so on. Use a functional map called MakeReport, to produce one report per flower type.
To create a report for each flower type, you need to determine the different kinds of flowers in the input data. To do this, use the UNIQUE function. The UNIQUE function looks at all of the values for a given data object and returns the unique values.
In the input data, the object called Flower indicates the flower type. Use the UNIQUE function on Flower as the first input argument to the map F_MakeReport. This will cause the map F_MakeReport to be executed once for each flower type.
In the input data, the unique flowers are alstromeria, daisy, snapdragon, lily, and iris. In each output report for a given flower type, you want all of the ProgressReadings for that flower type, which are scattered throughout the entire input data. To get all of these ProgressReadings, you will use the entire input object as the second argument to the map F_MakeReport.