vlookup: Excel-like 'VLOOKUP' function

View source: R/all.R

vlookupR Documentation

Excel-like VLOOKUP function

Description

Works just like Excel's VLOOKUP function with a few improvements.

Usage

vlookup(
  lookup_value,
  table_array,
  col_index_number,
  type = 0,
  lookup_index = 1
)

Arguments

lookup_value

a vector of values you want to match in the table_array column of interest

table_array

the data you are "looking up" in

col_index_number

the index of the column you want to return

type

0 = exact match. No other method is currently supported

lookup_index

the column index of the column lookup_value is matched to (In Excel, this is always "1")

Value

Returns a vector of values with the same length as lookup_value. If a value is not found, then NA is returned. Unlike Excel, the column we are matching against cannot have duplicates.

Examples

ref <- data.frame(
  state = c('UT', 'FL', 'NY', 'CA', 'SD'),
  category = c(1, 2, 3, 3, 1)
)

vlookup('CA', ref, 1, 0)
vlookup('CA', ref, 2, 0)

vlookup(c('CA', 'FL', 'KY'), ref, 2, 0)

ref[2, 2] <- 4
vlookup('FL', ref, 2, 0)



adamleerich/alrtools documentation built on March 12, 2024, 11:38 p.m.