R- Error "survfit" formula, survival package

5.1k views Asked by At

I'm learning basics about survival package in R with this tutorial

I followed the steps and got an error: The data is in the package:

aml<-aml

And in page 2 of the tutorial:

summary(survfit(Surv(aml$time[1:11],aml$status[1:11])))
Error in UseMethod("survfit", formula) : 
  no applicable method for 'survfit' applied to an object of class "Surv"

So, I tried:

train<-Surv(aml$time[1:11],aml$status[1:11])
survfit(Surv(time, status), data = train) 

And I got another error:

Error in Surv(time, status) : Time variable is not numeric

Really I don't know what I'm doing and why the steps from the tutorial are wrong.

1

There are 1 answers

0
Kshitij Dixit On

You should convert your time variable to numeric type using following:

train$time = as.numeric(train$time)