I've got a dataframe named df
on which I want to convert amounts in certain columns in euros (given by the variable $currency.Code). For this, I've got another dataframe named taux_change_vers_EUR
with two variables: (1) the name of the currency, (2) the exchange rate to convert in euros.
I would like to apply the coefficients of the second column of my dataframe taux_change_vers_EUR
to several columns of my dataframe df
. The problem is that my df is quite large and so the operation has to be optimized (nor for loop). Do you have an idea?
Here is a part of code. This code does not work but does show you what I'm expecting:
for (devise in unique(df$currency.Code)){
df[df$currency.Code==devise,c(4:37,44:48)] <- df[df$currency.Code==devise,c(4:37,44:48)]*rep(as.numeric(taux_change_vers_EU R[taux_change_vers_EUR[,1]==devise,2]),39)
}
Here is how my second dataframe looks like:
taux_change_vers_EUR
V1 V2
1 USD 1.14720
2 CAD 1.48836
3 GBP 0.87869
4 EUR 1.00000
5 <NA> 1.00000
6 DKK 6.50221
7 SEK 9.10235
8 PLN 3.76455
9 CZK 22.49280
10 NOK 8.28273
11 TRY 6.12973
12 TWD 30.98320
13 CNY 6.92256
14 HKD 7.83296
15 JPY 113.16000