xlookup: Excel-like 'XLOOKUP' function

View source: R/all.R

xlookupR Documentation

Excel-like XLOOKUP function

Description

Works like Excel's XLOOKUP function

Usage

xlookup(
  x,
  lookup_vector,
  return_vector = NULL,
  warn = TRUE,
  ignore_case = TRUE
)

Arguments

x

a vector of values you want to match in lookup_vector

lookup_vector

the vector to match in – get the index for return_vector

return_vector

the vector to return from

warn

TRUE will list values of x that are not found in lookup_vector

ignore_case

TRUE will do a case insensitive match of x on lookup_vector

Value

Returns a vector of values with the same length as lookup_vector. If a value is not found, then NA is returned. NA can be mapped to a non-NA value.

Examples

ref <- data.frame(
  state = c('UT', 'SD', 'FL', NA, 'NY', 'CA'),
  category = c(1, 2, 5, 10, 6, 7)
)

xlookup('CA', ref$state, ref$category)
xlookup('KY', ref$state, ref$category)
xlookup(NA, ref$state, ref$category)


adamleerich/alrtools documentation built on Dec. 16, 2024, 8:49 a.m.