R/fbind.R

#' Bind two factors
#'
#' Create a new factor from two existing factors, where the new factor's levels
#' are the union of the levels of the input factors.
#'
#' @param a factor
#' @param b factor
#'
#' @return factor
#' @export
#' @examples
#' fbind(iris$Species[c(1, 51, 101)], PlantGrowth$group[c(1, 11, 21)])
fbind <- function(a, b) {
  stopifnot(is.factor(a)||is.character(a))
  stopifnot(is.factor(b)||is.character(b))

  factor(c(as.character(a), as.character(b)))
}
derekcho/foofactors documentation built on May 15, 2019, 3:58 a.m.