0

the survfit() function will not accept a list, so I need a way to unlist the result of Surv() without removing information from the column. For example, using the lung data:

library(survival)

attach(lung)

lung$survObj <- with(lung, Surv(time, status ==2))
lung.2 <- lung
mylist <- list(lung,lung.2)

Here is an attempt to use lung from my list and pass lung$survObj into `survfit() and group by column 5 (sex):

survfit(formula = mylist[[1]][11] ~ mylist[[1]][5], data = mylist[[1]])

invalid type (list) for variable 'mylist[[1]][11]'

but given the following:

nrow(mylist[[1]][11])

228

and

length(unlist[[1]][11])

456

i.e. double!

I get the obvious complaint that I am comparing columns of unequal length.

also notice that the + symbols are removed after unlisting which is vital to survfit().

Has anyone managed to call survfit on a list of dataframes?

thanks.

brucezepplin
  • 9,202
  • 26
  • 76
  • 129

1 Answers1

1

Here are three possible solutions to your problem.

A)

survfit(survObj ~ sex, data=mylist[[1]])

B)

 Y1 <- mylist[[1]]$survObj
 x1 <- mylist[[1]]$sex
 survfit(Y1 ~ x1)

C)

Y2 <- mylist[[1]][11][[1]]
x2 <- mylist[[1]][5][[1]]
survfit(Y2 ~ x2)
Marco Sandri
  • 23,289
  • 7
  • 54
  • 58