Question for writing a function to pipe

My Question is about to write a function to pipe the data from survfit to ggsurvplot.

library(survival)
library(survminer)
s <- data_frame( time = c (10:19), event = c(1,0,1,0,1,0,1,1,0,1), hormone = c (1,0,1,0,1,1,1,0,1,0), 
            op= c(1,1,1,1,1,0,0,0,1,1))
survfit(Surv(time,event)~ hormone, data=s) %>% ggsurvplot(data=s)

A function seems similar, but not successful

u = c("hormone", "op")
f1 = function(x){survfit(Surv(time,event) ~ x, data=s) %>% ggsurvplot(data=s)}
lapply(s[u], f1)

Error in eval(inp, data, env) : object 'x' not found

Thanks for every opinion

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.