Home > other >  Ask a question about writing function in the for loop
Ask a question about writing function in the for loop

Time:04-27

The original code is as follows:
Tempfit & lt; - CPH (fit $formula, data=https://bbs.csdn.net/topics/mydata, x=T, T, y=surv=T)

Surv<- Survival (tempfit)
Surv1 & lt; - the function (x) surv (365 x)
Surv2 & lt; - the function (x) surv (365 * 2, x)
Surv3 & lt; - the function (x) surv (365 * 3, x)
Surv4 & lt; - the function (x) surv (365 * 4, x)
Surv5 & lt; - the function (x) surv (365 * 5, x)
Surv6 & lt; - the function (x) surv (365 * 6, x)
Surv7 & lt; - the function (x) surv (365 * 7, x)
Surv8 & lt; - the function (x) surv (365 * 8, x)
Surv9 & lt; Surv - function (x) (9, 365 * x)
Surv10 & lt; - the function (x) surv (365 * 10 x)
Nom & lt; - nomogram (tempfit, fun=flist [1 yr],
Fun. At=c (seq (. 1. 9, by=, 1)),
Funlabel=fl)

Surv for 10 years, according to the input of yr in nomogram yr a survival probability of the line, but if more than 10 years? If don't want to knock out one by one, into month impossible
So I use the following for loop to generate each surv [I]
Su & lt; - the list ()
For (I in 1:10) {
Su [I] <- the function (x) surv (365 * I, x)
}
Flist & lt; - the list (su1, su2, su3, su4, su5, su6, su7, su8, su9, su10)
But the error below
The Error in the su [I] <- the function (x) surv (365 * I, x) :
Always coerce a type 'closure' to the vector of type 'list'


Search thought surv has not been assigned at the beginning, by the system as a function of surv, I changed to su, but still error, I think it's su [I] <- function (x) surv (365 * I, x) the words on the right side of the surv (365 * I, x) the surv errors, but don't know how to change again, the ball ball old elder brothers for help
  • Related