I have vectors of time, status and gender and would like to do a Survival Analysis:
time <- c(306,455,1010,210,883,1022,310,361,218,166)
status <- c(0,1,0,1,0,0,1,0,1,1)
gender <- c("Male","Male","Female","Female","Male","Female","Female","Female","Female","Female")
A <- survfit(Surv(time, status)~gender)
Then I split the table:
library(broom)
library(dplyr)
B<-tidy(A, censored = TRUE) %>%
split(.$strata)
In that table I want certain column so I made a loop:
Time<-list()
Estimate<-list()
StdError<-list()
for (i in 1:length(B)){
Time[i] <- B[[i]][1]
Estimate[i] <- B[[i]][5]
StdError[i] <- B[[i]][6]
}
And when I try to extract and combine the column using cbind
and I get this result:
result <- cbind(Time, Estimate, StdError)
>result
Time Estimate StdError
[1,] Numeric,7 Numeric,7 Numeric,7
[2,] Numeric,3 Numeric,3 Numeric,3
Can somebody explain to me why this happened and help me to fix my code so that the output would come out like this:
>result
Time Estimate StdError
[1,] 166 0.8571429 0.1543033
166 0.8571429 0.1543033
210 0.7142857 0.2390457
218 0.5714286 0.3273268
310 0.4285714 0.4364358
361 0.4285714 0.4364358
1010 0.4285714 0.4364358
1022 0.4285714 0.4364358
[2,] Time Estimate StdError
306 1.0 0.0000000
455 0.5 0.7071068
883 0.5 0.7071068