Replace x values with corresponding values using a key

look_up(x, table, index = "var", column = 2)

Arguments

x

A string vector to be matched.

table

Lookup table

index

Character string of the key/index column used for matching

column

Column index (integer) or name (string) to return from the lookup table. Default is the second column.

Examples

library(magrittr)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
iris %>% .$Petal.Width %>%
 look_up(tibble(var=0.2,return="zero-point-two"))
#>   [1] "zero-point-two" "zero-point-two" "zero-point-two" "zero-point-two"
#>   [5] "zero-point-two" "0.4"            "0.3"            "zero-point-two"
#>   [9] "zero-point-two" "0.1"            "zero-point-two" "zero-point-two"
#>  [13] "0.1"            "0.1"            "zero-point-two" "0.4"           
#>  [17] "0.4"            "0.3"            "0.3"            "0.3"           
#>  [21] "zero-point-two" "0.4"            "zero-point-two" "0.5"           
#>  [25] "zero-point-two" "zero-point-two" "0.4"            "zero-point-two"
#>  [29] "zero-point-two" "zero-point-two" "zero-point-two" "0.4"           
#>  [33] "0.1"            "zero-point-two" "zero-point-two" "zero-point-two"
#>  [37] "zero-point-two" "0.1"            "zero-point-two" "zero-point-two"
#>  [41] "0.3"            "0.3"            "zero-point-two" "0.6"           
#>  [45] "0.4"            "0.3"            "zero-point-two" "zero-point-two"
#>  [49] "zero-point-two" "zero-point-two" "1.4"            "1.5"           
#>  [53] "1.5"            "1.3"            "1.5"            "1.3"           
#>  [57] "1.6"            "1"              "1.3"            "1.4"           
#>  [61] "1"              "1.5"            "1"              "1.4"           
#>  [65] "1.3"            "1.4"            "1.5"            "1"             
#>  [69] "1.5"            "1.1"            "1.8"            "1.3"           
#>  [73] "1.5"            "1.2"            "1.3"            "1.4"           
#>  [77] "1.4"            "1.7"            "1.5"            "1"             
#>  [81] "1.1"            "1"              "1.2"            "1.6"           
#>  [85] "1.5"            "1.6"            "1.5"            "1.3"           
#>  [89] "1.3"            "1.3"            "1.2"            "1.4"           
#>  [93] "1.2"            "1"              "1.3"            "1.2"           
#>  [97] "1.3"            "1.3"            "1.1"            "1.3"           
#> [101] "2.5"            "1.9"            "2.1"            "1.8"           
#> [105] "2.2"            "2.1"            "1.7"            "1.8"           
#> [109] "1.8"            "2.5"            "2"              "1.9"           
#> [113] "2.1"            "2"              "2.4"            "2.3"           
#> [117] "1.8"            "2.2"            "2.3"            "1.5"           
#> [121] "2.3"            "2"              "2"              "1.8"           
#> [125] "2.1"            "1.8"            "1.8"            "1.8"           
#> [129] "2.1"            "1.6"            "1.9"            "2"             
#> [133] "2.2"            "1.5"            "1.4"            "2.3"           
#> [137] "2.4"            "1.8"            "1.8"            "2.1"           
#> [141] "2.4"            "2.3"            "1.9"            "2.3"           
#> [145] "2.5"            "2.3"            "1.9"            "2"             
#> [149] "2.3"            "1.8"