Solution:
From the output of str(cc2)
, the variable within of the data.table, V1, is itself a list. This imply that cc2 is a nested list of length 1. The error is happening since table
calls sort.list
, which necessary an atomic vector as input.
Attempt employing unlist
:
cc3 <- as.data.frame(table(unlist(cc2)))
unlist
will extract elements from their list containers. Hence unlist(cc2)
will return a vector, which performs directly with table
.
I solved it by unlisting cc2 unli <- unlist(cc2)
thereafter converted it to df df<-as.data.frame(cc2)
As far as I can view, the issue is that you have a nested dataframe. I can't notify of any solution except unlisting the nested dataframe (converting it to a vector):
tk1_h$profile <- unlist(tk1_h$profile)
Attempt the following R code, which must work
library(survival)
data(veteran)
fit <- survfit(Surv(time, status)~trt, data = veteran)
survminer::ggsurvplot(fit, risk.table = TRUE)