I have two dataframes in R:
Dates<-as.Date(c("01/01/14","01/02/14","01/03/14","01/04/14","01/05/14","01/06/14","01/07/14","01/08/14","01/09/14","01/10/14","01/11/14","01/12/14"), "%d/%m/%y")
SGD<-c(0.710123, 0.706803,0.694468, 0.703793, 0.709672, 0.715876,0.721752,0.728214,0.740987,0.747695,0.744376,0.741504)
EUR<-c(1.230716,1.221853,1.217159,1.219232,1.220381,1.218245,1.215026,1.211793,1.207671,1.20807,1.202782,1.202307)
ExchangeRate <- data.frame(Dates,SGD,EUR)
and
Order_Date<-as.Date(c("01/01/14","11/01/14","02/02/14","10/03/14","01/05/14","01/06/14","22/07/14","01/08/14","18/09/14","01/10/14","23/11/14","01/12/14"), "%d/%m/%y")
Currency <-c("SGD","SGD","EUR","EUR","EUR","EUR","SGD","SGD","SGD","SGD","EUR","EUR")
Revenue<-c(10,20,30,40,50,60,70,80,90,100,110,120)
Customer<-data.frame(Order_Date,Currency,Revenue)
What I want to achieve is to create another column next to revenues with the revenue in EUR corresponding to the correct Date looking only at month and year (since the exchange rate is on a monthly basis).
Ex: in the first row of the table Customer, it should look in the table ExchangeRate what is the exchange rate corresponding to January 2014 for SGD and return a new column with the total revenue in EUR -> 10*0.71 = 7.1 and do the same for each row.