explode: Explode/implode data frame column(s).

View source: R/PA.EMOA.dataprocessing.R

explodeR Documentation

Explode/implode data frame column(s).

Description

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.

Usage

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.

Value

[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)

ecr documentation built on March 31, 2023, 10:07 p.m.