使用简单的乘法
set.seed(1223) g.rates[x[, 5], ] * x[, -5] # Note in your question you missed to include Typ2.rates
或者使用data.table
library(data.table) setDT(x)[, .SD*g.rates[x$Type,] , .SDcols = paste0("V", 1:4)] # V1 V2 V3 V4 #1 141.8580 1149.9857 303.4235 1014.77952 #2 770.1482 407.0248 1219.3383 156.62141 #3 554.1117 983.2340 239.1585 50.52443 #4 584.8300 1207.7605 2252.7681 43.13052