krangl / krangl / bindRows

bindRows

fun DataFrame.bindRows(df: DataFrame): DataFrame
fun DataFrame.bindRows(vararg someRows: DataFrameRow): DataFrame
fun bindRows(vararg dataFrames: DataFrame): DataFrame

Adds new rows. Missing entries are set to null. The output of bindRows() will contain a column if that column appears in any of the inputs.

When row-binding, columns are matched by name, and any missing columns will be filled with NA.

Grouping will be discarded when binding rows.

val places = dataFrameOf(
        "name", "population")(
        "Fort Joy", 150,
        "Cloudsdale", 2000
)

// You can add multiple rows at the same time.
places.bindRows(
        mapOf("name" to "Tristram", "population" to 72),
        mapOf("name" to "Paper Town", "population" to 0)
)

// Adding incomplete rows inserts nulls
places.bindRows(mapOf("population" to 10), mapOf("name" to "Paper Town"))

// To drop additional columns originating from the bound rows simply select
places.bindRows(mapOf("name" to "Bucklyn Cross", "area" to 52.2)).select(places.names)

// Grouping is discarded when adding rows and needs to be reconstituated
places.groupBy("name")
        .bindRows(mapOf("population" to 10))
        // regroup
        .groupBy("name")