R/this_in_that.R

Defines functions this_in_that

Documented in this_in_that

#' Where is this in that?
#'
#' Looks up (matches) the position of \code{this} in \code{that} (table)
#'
#' @param this Values to look up in that
#' @param that Value positions matched to this
#' @param value Optional, values to be returned rather than the default, which
#'   returns positions (integers)
#' @export
this_in_that <- function(this, that, value = NULL) {
  m <- match(this, that)
  if (is.null(value)) {
    return(m)
  }
  if (length(that) != length(value)) {
    stop("'value' must be same length as 'that' (table)", call. = FALSE)
  }
  value[m]
}

Try the tfse package in your browser

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

tfse documentation built on May 2, 2019, 11:28 a.m.