Skip to content
Prev 308428 / 398503 Next

Looping survdiff

The number of recent questions from umn.edu makes me wonder if there's homework involved....

Simpler for your example is to use get and subset.
dat <- structure(.....    as found below
var.to.test <- names(dat)[4:6]   #variables of interest
nvar <- length(var.to.test)
chisq <- double(nvar)
for (i in 1:nvar) {
     tfit <- survdiff(Surv(time, completion==2) ~ get(var.to.test[i]), data=dat, 
subset=(group==3))
     chisq[i] <- tfit$chisq
     }
write.csv(data.frame(var.to.test, chisq))
On 10/19/2012 05:00 AM, r-help-request at r-project.org wrote: