Vlookup replace using a lookup column and reference table
vlookup_from_ref.Rd
Vlookup replace using a lookup column and reference table
Arguments
- base
vector
of starting values. Replacements will be made in this vector before it is returned.- lookup_col
vector
of values with same length asbase
that will be matched tolookup_ref
to deteremine the replacement indices- lookup_ref
vector
of reference values, whichlookup_col
will be matched to in order to determine replacement values.- value_col
vector
of replacement values with same length aslookup_ref
See also
Other vectors:
len_unique()
,
names_values_switch()
,
rle_df()
,
rle_groups()
,
rle_seq()
,
sort_by_names()
,
true_names()
,
unify_vec_preserve_order()
,
unique_with_names()
,
vlookup()
,
zchar_remove()
Examples
ref <- tibble::tibble(lookup = letters[1:5], value = 1:5)
original <- tibble::tibble(lookup = letters[1:20], base = runif(20, min = 6, max = 20))
dplyr::mutate(original, base = vlookup_from_ref(base, lookup, ref$lookup, ref$value))
#> # A tibble: 20 × 2
#> lookup base
#> <chr> <dbl>
#> 1 a 1
#> 2 b 2
#> 3 c 3
#> 4 d 4
#> 5 e 5
#> 6 f 17.9
#> 7 g 7.49
#> 8 h 12.8
#> 9 i 9.46
#> 10 j 15.6
#> 11 k 8.29
#> 12 l 19.3
#> 13 m 10.5
#> 14 n 11.1
#> 15 o 18.4
#> 16 p 17.6
#> 17 q 7.41
#> 18 r 18.7
#> 19 s 16.8
#> 20 t 11.4