Вот один из возможных способов:
#Please include all currencies that you have
currency <- c('AUD', 'GBP', 'EUR')
#Loop over each of them
do.call(cbind, lapply(currency, function(x) {
#Find all the columns with that currency
group_cols <- grep(paste0('cost_', x), names(df))
#Get the exhange rate column
col_to_multiply <- grep(paste0('ER_', x), names(df))
#Repeat the exchange rate column same as total columns and multiply
df[group_cols] * df[rep(col_to_multiply, length(group_cols))]
}))
или аналогично purrr::map_dfc
purrr::map_dfc(currency, ~{
group_cols <- grep(paste0('cost_', .x), names(df))
col_to_multiply <- grep(paste0('ER_', .x), names(df))
df[group_cols] * df[rep(col_to_multiply, length(group_cols))]
})