2

I have a dataframe with 18 different currencies over 11 years and would like to convert them all to USD using year-end exchange rates for each year.

Basically, I want to convert the value of EUR in 2011 at the USD exchange rate on 31/12/2011, the value in CAD in 2011 at the USD exchange rate on 31/12/2011, the value of EUR in 2012 at the USD exchange rate on 31/12/2012... so on and so forth.

Using priceR, I can do this:

lapply(currency_codes, function (x) historical_exchange_rates(from = x, to = "USD", start_date = "2011-12-31", end_date = "2011-12-31")  )

and create a list with all the exchange rates for each currency for 2011. Then I do the same for all the other years, cbind them and then add it to the original dataframe.

However, I imagine there is a better way to do this, so my question is: is there a way to streamline this?

Thanks in advance!

maplesyrup123
  • 303
  • 1
  • 6

0 Answers0