vlookup: vlookup

Description Usage Arguments Value Examples

Description

This function is an implementation of the vlookp function from Excel. It is used to return values from a column in a data frame, which correspond to certain values in another column in the same data frame. These other values are taken as input for the function.

Usage

1
2
vlookup(data, look.for, look.in, return.from, return.multiple = FALSE,
  return.na = TRUE)

Arguments

data

A data frame in which the values should be looked up

look.for

The values to look for in the column look.in in the data frame.

look.in

The column to which the values from look.for are matched.

return.from

The column from which the corresponding values are returned.

return.multiple

If one value from look.for would return multiple values from return.from, should these multiple values be returned? Default is to FALSE.If set to FALSE and multiple matches occur, an error is returned.

return.na

Should missing values be returned? Defaul is to TRUE.

Value

A vector with the corresponding values from the column return.from. Length must not be the same as look.for, but usually is if return.multiple = FALSE and return.na = TRUE and all values from look.for are in look.in.

Examples

1
2
3
4
data <- data.frame(a = c(1, 2, 3, 5, 5, 3, NA, 4, 4),
b = c("A", "B", "C", "D", "D", "E", "F", "D", NA),
stringsAsFactors = TRUE)
vlookup(data, look.for = c(1, 5), look.in = "a", return.from = "b", return.multiple=TRUE, return.na = TRUE)

kthorstmann/horst documentation built on May 20, 2019, 7:04 p.m.