R/bt_bind.R

Defines functions bt_bind

Documented in bt_bind

# Roxygen documentation

#' Bastiat, rbind two data frames.
#'
#' Shortcut to rbind two data frames with possibly diverging column names. Divergent columns are filled with NA's in the frame where it is absent.
#'
#' @return a data frame.
#' @references www.globaltradealert.org
#' @author Johannes Fritz for GTA


# Function infos and parameters  --------------------------------------------

bt_bind <- function(x, y) {
  x.diff <- setdiff(colnames(x), colnames(y))
  y.diff <- setdiff(colnames(y), colnames(x))

  x[, c(as.character(y.diff))] <- NA
  y[, c(as.character(x.diff))] <- NA

  x <- as.data.frame(x)
  y <- as.data.frame(y)

  return(rbind(x, y))
}
global-trade-alert/gtabastiat documentation built on June 4, 2023, 6:40 a.m.