Hi,
If i understood correctly, I would go like that
# with vectors
variance_vec <- c('Material A' = 0.8, 'Material B' = 0.21)
mat_vect <- c('Material A',
'Material D',
'Material B',
'Material A')
variance_vec[mat_vect]
#> Material A <NA> Material B Material A
#> 0.80 NA 0.21 0.80
Also, in such case, I would work with data.frame and use dplyr and other tidyverse. I could really help once the case become more complex than simple vetor.
You have nice join fonctions that works well.
library(dplyr)
# using enframe to simplify vector -> df transformation
variance_df <- tibble::enframe(variance_vec)
variance_df
#> # A tibble: 2 x 2
#> name value
#> <chr> <dbl>
#> 1 Material A 0.8
#> 2 Material B 0.21
# this is like a data.frame but with nice printing
mat_df <- tibble(name = mat_vect)
mat_df
#> # A tibble: 4 x 1
#> name
#> <chr>
#> 1 Material A
#> 2 Material D
#> 3 Material B
#> 4 Material A
# table operation : join
mat_df %>%
left_join(variance_df, by = 'name')
#> # A tibble: 4 x 2
#> name value
#> <chr> <dbl>
#> 1 Material A 0.8
#> 2 Material D NA
#> 3 Material B 0.21
#> 4 Material A 0.8
Created on 2019-05-07 by the reprex package (v0.2.1.9000)