我有一TRX对日期和Curreny 的df
Date Currency ExchangeRate
2012-08-13 EUR ?
2012-08-13 CHF ?
2012-08-13 CZK ?
Run Code Online (Sandbox Code Playgroud)
我有第二个df CURRENCIES货币兑换率与欧元基数.
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
Run Code Online (Sandbox Code Playgroud)
现在我想翻译日费率.我为这个liske getDayRate(日期,货币)写了一个函数.
getDayRate <- function(date, currency) {
currencies[which(as.character(currencies[,c("Date")]) == date),c(currency)]
}
getDayRate("2013-06-20","EUR")
Run Code Online (Sandbox Code Playgroud)
现在我想应用于getDayRate(date,currency)每一行,TRX以便每行使用第一个和第二个元素作为参数,所以我得到了ExchangeRate.
apply(x,1,fun())不起作用,因为它需要一个带数字的矩阵.理论上,我必须将数据帧转换为索引,然后使用apply.
有没有更好的办法?