Learn R Programming

lplyr (version 0.1.6)

fuse: Fuse multiple columns into one

Description

fuse is a more flexible version of unite from package tidyr.

Usage

fuse(.data, col, ..., fun = concat0, remove = TRUE)
fuse_(.data, col, from, fun = concat0, remove = TRUE)
"fuse_"(.data, col, from, fun = concat0, remove = TRUE)
"fuse_"(.data, col, from, fun = concat0, remove = TRUE)

Arguments

.data
A tbl or data.frame
col
character. (Bare) name of column to add
...
Specification of columns to fuse.
fun
function. The function to be applied (concat0 by default).
remove
logical. If TRUE (the default), remove input columns from output data frame.
from
character. A vector of the names of columns to fuse.

See Also

unite and unite_ from package tidyr;

concat0 from package bazar.

Examples

Run this code
df <- data.frame(x = c(NA, "a", NA), 
                 y = c("b", NA, NA))
fuse(df, "z", x, y)

# To be compared with: 
tidyr::unite(df, "z", x, y, sep = "")
# The same
fuse(df, "z", x, y, fun = function(x) concat0(x, na.rm = FALSE))

Run the code above in your browser using DataLab