I have the following:
splits<-split(df,disease)
where I have split a datframe by column1. But I want to use the Surv function:
library(survival)
with(df,Surv(TIME,STATUS)~GENDER)
How do I extend this to my split dataset to run the Surv() function separately on each split dataset? I have tried using the sapply() function:
surv.obj<-sapply(splits, function(x) Surv(TIME,STATUS)~GENDER)
which seems to work fine because I get:
surv.obj
$heart_disease
Surv(TIME,STATUS)~GENDER
<environment: 0X0000000000000019cac10>
$cancer
Surv(TIME,STATUS)~GENDER
<environment: 0X0000000000000019cac11>
.
.
.
, however when trying to use the survfit function: survfit(surv.obj)
, I try to plot surv.obj$heart_disease I get
plot(suv.obj$heart_disease)
Error in Surv(TIME,STATUS) : object TIME not found
which clearly means the sapply statement has not done it's job. Could someone advise me what the correct sapply syntax should have been?