Map
Define key-value pairs
Last updated
Define key-value pairs
Last updated
The Map data type represents a collection of key-value pairs. It is a way to associate one piece of information with another, similar to "recode" function in R or SQL. It is like a two-column list.
A key-value pair consists of two related data elements, and it can be used a bit like an “if this, then that” statement (“if this key, then that value”).
Within a map, the Key must be unique, but the Value doesn't need to be unique. The Key is the unique identifier, and the Value is the information associated with the Key. Each Key is only associated with one Value, but the same Value can be assigned to multiple Keys.
The Extend-datatable adaptor accepts a Map for the values
argument. This argument should provide mapping such that for a given value in the `source` column, a corresponding value should appear in the target column.
If you have a spreadsheet containing a two-column set of column, column__colour then you can pull that into Data-flo and use extend-datatable to associate those colours with the rest of your data.
Again using Extend-datatable, we can harmonise inconsistent spellings using a data map.
TIP
: The map must include all desired key-value pairs. Don't forget to include the map of values that are not changing (e.g. not just "uk | UK" but also "UK | UK".
Given the following Datatable:
This map would assign a colour to each city:
Resulting in this Datatable:
TIP
: For a map that may need frequent editing or extension, you can create a dictionary/library of the mapped terms in an external file (csv, spreadsheet, etc).
TIP
: If mapping based on an existing column (e.g. in Extend-datatable), use datatable-to-list and unique-list-items to identify all the source column values and ensure that you include all necessary key-value pairs.