A simple implementation similar to the VLOOKUP function in Excel.

vlookup(this, df, key, value)

Arguments

this

The value to look up

df

A data frame

key

The column to look up

value

The column to return

Value

The value in the value column corresponding to the key column

Examples


df <- data.frame(key = c("a", "b", "c"), value = c(1, 2, 3))
print(misc::vlookup("b", df, "key", "value"))
#> [1] 2