associateBy
Builds a Map where each key is produced by applying transform to a row, and the value is the corresponding DataRow.
The transform is a RowExpression — a lambda that receives each DataRow both as this and it and is expected to return a key, allowing you to compute keys directly from row values. You can also use extension properties for concise and type-safe access.
If several rows produce the same key, the map keeps the last row for that key, consistent with Kotlin's kotlin.collections.associateBy behavior.
The keys are in the same order as the rows. A key that occurs in several rows appears at the position of its first row, with the row of its last one.
For more information: See associateBy on the documentation website.
See also:
associate— builds a map from key-valuePairs produced by transforming each row, so the values are computed instead of being the rows themselves.toMap— converts aDataFrameinto aMapby using column names as keys and their values as the corresponding map values.
Example
// Associate each row by the "id" column
val map = df.associateBy { id }Return
A Map of keys to corresponding rows.
Parameters
A RowExpression that returns a key for each row.