Object not found error with ddply inside a function

后端 未结 5 741
别跟我提以往
别跟我提以往 2020-11-30 01:58

This has really challenged my ability to debug R code.

I want to use ddply() to apply the same functions to different columns that are sequentially nam

5条回答
  •  旧时难觅i
    2020-11-30 02:18

    You can do this with a combination of do.call and call to construct the call in an environment where NewColName is still visible:

    myFunction <- function(x,y){
    NewColName <- "a"
    z <- do.call("ddply",list(x, y, summarize, Ave = call("mean",as.symbol(NewColName),na.rm=TRUE)))
    return(z)
    }
    
    myFunction(d.f,sv)
      b Ave
    1 0 1.5
    2 1 3.5
    

提交回复
热议问题