## Key

• This line was removed.
• Formatting was changed.
Excerpt

This example illustrates how to generate an Array that is a slice of an another Array, based on index numbers. The elements of this Array can then be merged into a String value.

Functions:

D generate list excerpts
pages ARRAYSLICE Function,ARRAYMERGEELEMENTS Function

Source:

The following set of arrays contain results, in order, of a series of races. From this list, the goal is to extract a list of the podium finishers for each race as a single string.

RaceIdRaceResults
1
["racer3","racer5","racer2","racer1","racer6"]
2
["racer6","racer4","racer2","racer1","racer3","racer5"]
3
["racer4","racer3","racer5","racer2","racer6","racer1"]
4
["racer1","racer2","racer3","racer5"]
5
["racer5","racer2","racer4","racer6","racer3"]

Transformation:

From the list of arrays, the first step is to gather the top-3 finishers from each race:

D trans
RawWrangle true 'arrPodium' step derive type: single value: ARRAYSLICE(RaceResults, 0, 3) as: 'arrPodium' Formula type Single row formula Formula ARRAYSLICE(RaceResults, 0, 3) New column name New formula

The above captures the first three values of the RaceResults arrays into a new set of arrays.

The next step is to merge this new set of arrays into a single string:

D trans
RawWrangle true 'strPodium' step derive type: single value: ARRAYMERGEELEMENTS(arrPodium, ',') as: 'strPodium' Formula type Single row formula Formula ARRAYMERGEELEMENTS(arrPodium, ',') New column name New formula

Results:

RaceIdRaceResultsarrPodiumstrPodium
1["racer3","racer5","racer2","racer1","racer6"]["racer3","racer5","racer2"]racer3,racer5,racer2
2["racer6","racer4","racer2","racer1","racer3","racer5"]["racer6","racer4","racer2"]racer6,racer4,racer2
3["racer4","racer3","racer5","racer2","racer6","racer1"]["racer4","racer3","racer5"]racer4,racer3,racer5
4["racer1","racer2","racer3","racer5"]["racer1","racer2","racer3"]racer1,racer2,racer3
5["racer5","racer2","racer4","racer6","racer3"]["racer5","racer2","racer4"]racer5,racer2,racer4

D s also
label example_arrayslice_and_arraymergeelements_functions