R/CollapseColumns.R

Defines functions SplitColumns CollapseColumns

# Collapsing dataframes columns in a single vector.
# This allows to find coincidences of all column values in a single comparison
CollapseColumns <- function(df, ..., sepMark = "--&&--")
{
  apply(cbind(df, ...), 1, paste, collapse = sepMark)
}

SplitColumns <- function(x, colNames = NULL, sepMark = "--&&--")
{
  res <- as.data.frame(t(simplify2array(strsplit(x, sepMark, fixed = TRUE))))
  colnames(res) <- colNames
  return(res)
}

Try the zoolog package in your browser

Any scripts or data that you put into this service are public.

zoolog documentation built on Aug. 26, 2022, 5:08 p.m.