explode function

Explode/implode data frame column(s).

Explode/implode data frame column(s).

Given a data frame and a column name, function explode splits the content of a column by a specified delimiter (thus exploded) into multiple columns. Function implode

does vice versa, i.e., given a non-empty set of column names or numbers, the function glues together the columns. Hence, functions explode and implode are kind of inverse to each other.

explode(df, col, by = ".", keep = FALSE, col.names = NULL) implode(df, cols, by = ".", keep = FALSE, col.name)

Arguments

  • df: [data.frame]

    Data frame.

  • col: [character(1)]

    Name of column which should be exploded.

  • by: [character(1)]

    Delimeter used to split cell entries (for explode) or glue them together (for implode).

  • keep: [logical(1)]

    Should exploded or imploded source column be kept? Default is FALSE.

  • col.names: [character]

    Names of new columns. Default is ‘col’.1 , ..., ‘col’.k , where k is the number of elements each cell in column col is split into.

  • cols: [character(1)]

    Names of columns (or column number) which should be imploded.

  • col.name: [character(1)]

    Name of new column.

Returns

[data.frame] Modified data frame.

Examples

df = data.frame(x = 1:3, y = c("a.c", "a.b", "a.c")) df.ex = explode(df, col = "y", col.names = c("y1", "y2")) df.im = implode(df.ex, cols = c("y1", "y2"), by = "---", col.name = "y", keep = TRUE)
  • Maintainer: Jakob Bossek
  • License: GPL-3
  • Last published: 2023-03-08