O'Reilly logo

Practical Predictive Analytics by Ralph Winters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Changing the data to reflect the second survey

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)[1] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required