R/strata.R

##' This is a special function used only in identifying the strata variables
##' when defining an \code{exactMatch} during a call to \code{fullmatch},
##' \code{pairmatch}, or \code{match_on}. It should not be called externally.
##'
##' @title Identify Stratafication Variables
##' @param ... any number of variables of the same length.
##' @return the variables with appropriate labels
##' @export
##' @examples
##' data(nuclearplants)
##' fullmatch(pr ~ cost + strata(pt), data = nuclearplants)
strata <- function (...)
{
  allf <- list(...)
  if (!all(vapply(allf, length, 1) == length(allf[[1]]))) {
    stop("Variables in `strata` must be same length")
  }
  d <- do.call(paste, allf)
  strata_NA <-  apply(vapply(allf, is.na, logical(length(d))), 1, any)
  d[strata_NA] <- NA
  d
}

Try the optmatch package in your browser

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

optmatch documentation built on Nov. 16, 2023, 5:06 p.m.