explode {ecr} | R 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 |
[ |
col |
[ |
by |
[ |
keep |
[ |
col.names |
[ |
cols |
[ |
col.name |
[ |
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)