I want to run a function (in this case just a multiplication) on two list based on their names. Here some example data showing my structure:
A <- list(\"111\"
You can use Map
to loop over B and B names, this will also keep up the names:
Map(function(x,y) A[[y]]*x, B, gsub('\\..*','',names(B)))
#$`111.2000`
# [,1] [,2] [,3]
#[1,] 36 18 54
#[2,] 16 25 3
#[3,] 56 10 20
#$`112.2000`
# [,1] [,2] [,3]
#[1,] 18 10 40
#[2,] 35 18 60
#[3,] 3 63 16
#$`111.2001`
# [,1] [,2] [,3]
#[1,] 81 30 18
#[2,] 56 25 1
#[3,] 28 20 16
#$`112.2001`
# [,1] [,2] [,3]
#[1,] 36 30 72
#[2,] 30 30 6
#[3,] 5 56 4