“Object not found” error within a user defined function, eval() function?

后端 未结 1 1285
[愿得一人]
[愿得一人] 2021-01-25 08:02

I\'m trying to write a function for a task I need to do many times (running a cox proportional hazards function over multiple imputed datasets). When I pass the necessary objec

相关标签:
1条回答
  • 2021-01-25 08:57

    Try this. You need to keep in mind that R doesn't know what's my.time and my.event. You have to parse them with quotes and then unqoute them in order to parse it into Surv

    myfun<-function(dflist,time,event){
      for (i in 1:length(dflist)){
        time <- noquote(time)
        event <- noquote(event)
        out<-cch(Surv(dflist[[i]][, time], dflist[[i]][, event])~as.factor(my.det), data=dflist[[i]], 
                 subcoh=~sub, id=~my.id, cohort.size=500)
        print(out)}
    }   
    myfun(my.list,"my.time","my.event")
    
    0 讨论(0)
提交回复
热议问题