我在R中创建了一个自定义函数,我想根据一些用户输入做一个cox模型,我的实际公式是这个
coxmodel <- function(time= time, status = status, covariate = covariate, dataset = dataset) {
modellocox <- eval(parse(text = paste("coxph(Surv(", time, ", ", status, "==2) ~", covariate, ", data=", dataset)))
testproporz <- cox.zph(modellocox)
}
但是我收到此错误消息
Error in paste("coxph(Surv(", time, ", ", status, "==2) ~", covariate, :
object "age" not found
如何创建一个函数,该函数接受字符串用户输入并根据该函数创建公式?
答案 0 :(得分:0)
您在paste("coxph(Surv(", time, ", ", status, "==2) ~", covariate,
R
中未定义年龄值正在搜索其值。