I have df TRX with Date and Curreny pairs
Date Currency ExchangeRate 2012-08-13 EUR ? 2012-08-13 CHF ? 2012-08-13 CZK ?
I have a second df CURRENCIES for currency conversion rates with EUR base.
Date EUR CHF CZK 2012-08-13 1 1.24 25.73 2012-08-13 1 1.23 25.92 2012-08-13 1 1.22 24.00
Now I want to translate daily rates. I wrote a function for this liske getDayRate (date, currency).
getDayRate <- function(date, currency) { currencies[which(as.character(currencies[,c("Date")]) == date),c(currency)] } getDayRate("2013-06-20","EUR")
Now I want to apply getDayRate(date,currency) to each TRX line so that for each line it uses the first and second elements as arguments, so I get teh ExchangeRate .
apply(x,1,fun()) does not work, since this requires a matrix with numbers. Theoretically, I would have to convert the data to indexes and then use apply.
Is there a better way?
source share