2013-11-03 3 views
1

내가 부모 기능과 자식 기능이 어떻게 제대로

edit를 참조 중첩 된 함수에 줄임표를 사용합니다. 내 자식 기능에 ... 기능을 사용하고 싶습니다. 특히 내가 제대로 내 아이 함수에서 코드의 이러한 특정 행에 ...을 사용하는 방법을 궁금 :

function(theList,...){ 

    #### 
    CombinedList=lapply(seq_along(theList), function (x,...) { 

    .x <- as.list(substitute(list(...)))[-1] 

    elementz=data.frame(rbind(.x[1][[x]],.x[2][[x]],.x[3][[x]])) 

...... 목록의 각 요소가리스트 즉, 목록의 목록이 있어야한다. 내 주 (마스터) 기능에서 ...SharpListSortinoList을 포함합니다.

windowSize=36 

    PerformanceDF <- function(data,windowSize,AvgForvalt=(0.02/12)){ 
     require(quantmod,quietly = TRUE) 
     require(reshape2,quietly = TRUE) 
     require(PerformanceAnalytics,quietly = TRUE) 
     require(xts,quietly = TRUE) 

     #36 mån rolling window list 

     windows <- embed(1:nrow(data), windowSize) 

     lapplyApproach <- function(data, windows) { 
     windowsList <- split(t(windows), rep(1:nrow(windows), each=ncol(windows))) 
     names(windowsList) <- unlist(lapply(windowsList, 
              function(x) data[x[1],1])) 
     return(lapply(windowsList,function(x) data[rev(x),])) 
     } 


     DropBench=grep("Benchmark",names(hedgesample),ignore.case=TRUE) 
     data=data[,-c(DropBench)] 

     theList=lapplyApproach(data,windows) 


     ##xts 

     theListXts=lapply(theList,function(x){ 

     blab=xts(x[,-1],as.Date(x[,1])) 

     return(blab) 

     }) 



     ##Sharpe Ratio  
     SharpList=lapply(theListXts,function(x) { 

     hej=SharpeRatio(x,FUN="StdDev") 

     rownames(hej)=NULL 

     hej[is.infinite(hej)] <- 0 

     return(hej) 

     }) 

     ##Sortino ratio 

     SortinoList=lapply(theListXts,function(x) { 

     mmm=SortinoRatio(x) 

     rownames(mmm)=NULL 

     mmm[is.infinite(mmm)]<-0 

     return(mmm) 

     }) 




     function(theList,...){ 




     #### 
     CombinedList=lapply(seq_along(theList), function (x,...) { 

     .x <- as.list(substitute(list(...)))[-1] 

     elementz=data.frame(rbind(.x[1][[x]],.x[2][[x]],.x[3][[x]])) 

     rownames(elementz)=NULL 

     elementz$Statistic=.x 

     return(elementz) 


     },...) 

     names(CombinedList)=names(theList) 

     return(CombinedList)}} 

은 지금 나는 error

Error in .x[1][[x]] : subscript out of bounds 
In addition: Warning messages: 
1: In rbind(.x[1][[x]], .x[2][[x]]) : 
    (symbol) object cannot be coerced to type 'list' 
2: In rbind(.x[1][[x]], .x[2][[x]]) : 
    (symbol) object cannot be coerced to type 'list' 
3: In rbind(.x[1][[x]], .x[2][[x]]) : 
    (symbol) object cannot be coerced to type 'list' 

안부를 얻을!

function(theList,...){ 

    CombinedList=lapply(seq_along(theList), function (x,...) { 

    .x <- as.list(substitute(list(...)))[-1] 

    elementz=data.frame(rbind(eval(.x[[1]])[[x]],eval(.x[[2]])[[x]],eval(.x[[3]])[[x]])) 

그러나 사람이 더 좋은 해결책을 가지고 않습니다

EDIT

해결책을 발견하셨습니까?

+0

'? do.call'을 참조하십시오. – fotNelton

+0

@fotNelton 음 ... 솔루션을 찾았습니다 CombinedList = lapply (seq_along (theList), function (x, ...) { .x <- as.list (대체 (list (...))) [- 1] elementz = data.frame (rbind (eval (.x [[1])) [[x]], eval (.x [[2]]) [[x]], eval (.x [ 3]) [X])) rownames (elementz) = NULL elementz $ 통계 = as.character (.x를) 창 (elementz) }, ...) – user1665355

+0

올려주세요 답변이 아니라 코멘트. – zero323

답변

0
function(theList,...){ 

    CombinedList=lapply(seq_along(theList), function (x,...) { 

    .x <- as.list(substitute(list(...)))[-1] 

    elementz=data.frame(rbind(eval(.x[[1]])[[x]],eval(.x[[2]])[[x]],eval(.x[[3]])[[x]]))