The following code uses the survSplit function to create a new record a time period 6 that will reflect the response to a second hypothetical customer survey administered at that time.
Copy the following code and run it in a new script window:
library(survival)SURV2 <- survSplit(data = ChurnStudy, id="ID.char", cut = 6, end = "Xtenure2", start = "time0", event = "Churn", episode="period")SURV2$CustomerID <- as.integer(SURV2$ID.char)SURV2 <- SURV2[order(SURV2$CustomerID),]
In the R console, execute the following commands to see how the dataframe has grown larger. Because we are splitting records at the mid-point (6 months), we have almost doubled the original records:
> nrow(ChurnStudy) ...