Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space DEV and version r095
Excerpt

This section describes how to flatten the values in an Array into separate rows in your dataset.

Source:

In the following example dataset, students took the same test three times, and their scores were stored in any array in the Scores column.

LastNameFirstNameScores
AdamsAllen[81,87,83,79]
BurnsBonnie[98,94,92,85]
CannonChris[88,81,85,78]

Transformation:

When the data is imported, you might have to re-type the Scores column as an array:

D trans
RawWrangletrue
Typestep
WrangleTextsettype col: Scores type: 'Array'
p01NameColumns
p01ValueScores
p02NameNew type
p02ValueArray
SearchTermChange column data type

You can now flatten the Scores column data into separate rows:

D trans
RawWrangletrue
Typestep
WrangleTextflatten col: Scores
p01NameColumn
p01ValueScores
SearchTermExpand Array into rows

Results:

LastNameFirstNameScores
AdamsAllen81
AdamsAllen87
AdamsAllen83
AdamsAllen79
BurnsBonnie98
BurnsBonnie94
BurnsBonnie92
BurnsBonnie85
CannonChris88
CannonChris81
CannonChris85
CannonChris78
Tip

Tip: You can use aggregation functions on the above data to complete values like average, minimum, and maximum scores. When these aggregation calculations are grouped by student, you can perform the calculations for each student.

D s also
labelexample_flatten_an_array