vlookup | R Documentation |
VLOOKUP
functionWorks just like Excel's VLOOKUP
function
with a few improvements.
vlookup(
lookup_value,
table_array,
col_index_number,
type = 0,
lookup_index = 1
)
lookup_value |
a vector of values you want to match in the |
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 |
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.