我有一个 dtl 表和一个查找表(GLMap)
分:
DEAL_TYPE DN_DIRECTION key COMPANY_CODE GLAccount
POWER SALE 1 AFFL_CO 1702
POWER PURCHASE 2 AFFL_CO 3702
MISC SALE 3 AFFL_CO 5717
MISC PURCHASE 4 AFFL_CO 5718
POWER SALE 5 AFFL_CO 1702
POWER SALE 6 MAIN
POWER PURCHASE 7 MAIN
MISC SALE 8 MAIN
MISC PURCHASE 9 MAIN
POWER SALE 10 MAIN
查找表(GLAcctMap):
DealType DR_CR GLAccount Customer
POWER P 3702 AFFL_CO
POWER S 1702 AFFL_CO
MISC P 5718 AFFL_CO
MISC S 5717 AFFL_CO
POWER P 6702 STD
POWER S 6712 STD
MISC P 5312 STD
MISC S 5313 STD
Expected Output: DEAL_TYPE DN_DIRECTION key COMPANY_CODE GLAccount GLACCT POWER S 1 AFFL_CO 1702 1702 POWER P 2 AFFL_CO 3702 3702 MISC S 3 AFFL_CO 5717 5717 MISC P 4 AFFL_CO 5718 5718 POWER S 5 AFFL_CO 1702 1702 POWER S 6 MAIN 6712 POWER P 7 MAIN 6702 MISC S 8 MAIN 5313 MISC P 9 MAIN 5312 电源 S 10 MAIN 6712
我想创建一个输出表,它是 dtl 表的副本,但根据查找表中多个列的匹配添加了一个额外的 GLACCT 列。
逻辑是:如果 GLAccount 列为空,则从查找表 (GLacctMap) 中获取匹配的帐户,否则将 GLAccount 编号放入新列中。
这是我尝试的一个功能:
load_details <- function(dld) {
phys_fin = 0
findgl <- function(x){
if( is.na(x$GLAccount) ) {
GLACCT <- GLacctMap[ match( paste(x$DEAL_TYPE, x$DN_DIRECTION, sep=":"),
paste( GLacctMap$DealType,GLacctMap$DR_CR,sep=":")), "GLAccount"]
} else {
GLACCT <- x$GLAccount
}
GLACCT
}
dld$GLACCT <- apply(currdld, 1, function(x) findgl )
}
PEDLD <- load_details(currdld)
我收到以下错误:IBCO Spotfire Statistics Services 返回了一个错误:'as.data.frame.default(passed.args[[i]], stringsAsFactors = s 中的错误:无法将类 '"function"' 强制转换为数据。框架'。