[R] Convert results from print(survfit(formula, ...)) into a matrix or data frame

Marc Schwartz marc_schwartz at me.com
Mon Apr 15 18:51:30 CEST 2013


On Apr 15, 2013, at 11:31 AM, Paul Miller <pjmiller_57 at yahoo.com> wrote:

> Hello All,
> 
> Below is some sample survival analysis code. I'd like to able to get the results from print(gehan.surv) into a matrix or data frame, so I can manipulate them and then create a table using odfWeave. Trouble is, I'm not quite sure how make such a conversion using the results from a print method.
> 
> Is there some simple way of doing this?
> 
> Thanks,
> 
> Paul
> 
> require(survival)
> require(MASS)
> 
> attach(gehan)
> gehan.surv <- survfit(Surv(time, cens) ~ treat, data= gehan, conf.type = "log-log")
> print(gehan.surv)
> 



Hi Paul,

If I am correctly understanding the output that you want to save, which is the summary results table output:

> gehan.surv
Call: survfit(formula = Surv(time, cens) ~ treat, data = gehan, conf.type = "log-log")

              records n.max n.start events median 0.95LCL 0.95UCL
treat=6-MP         21    21      21      9     23      13      NA
treat=control      21    21      21     21      8       4      11


You can use:

> summary(gehan.surv)$table
              records n.max n.start events median 0.95LCL 0.95UCL
treat=6-MP         21    21      21      9     23      13      NA
treat=control      21    21      21     21      8       4      11


> str(summary(gehan.surv)$table)
 num [1:2, 1:7] 21 21 21 21 21 21 9 21 23 8 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:2] "treat=6-MP" "treat=control"
  ..$ : chr [1:7] "records" "n.max" "n.start" "events" ...


See ?summary.survfit and note the 'table' part of the Value section.

Regards,

Marc Schwartz



More information about the R-help mailing list