1. Learn
  2. /
  3. Courses
  4. /
  5. Machine Learning for Marketing Analytics in R

Exercise

Data for survival analysis

In the following exercises you are going to work with data about customers of an online shop in order to practice survival analysis. But now it's not about the time until churn, but about the time until the second order.

The data is stored in the object dataNextOrder. The variable boughtAgain takes the value 0 for customers with only one order and 1 for customers who have placed a second order already. If a person has ordered a second time, you see the number of days between the first and second order in the variable daysSinceFirstPurch. For customers without a second order, daysSinceFirstPurch contains the time since their first (and most recent) order.

The ggplot2 package is already loaded to your workspace.

Instructions

100 XP
  • Take a look at the data using head().
  • Plot a histogram of the days since the first purchase separately for customers with vs. without a second order. (If you're not used to ggplot2 code, don't worry: You just have to use the daysSinceFirstPurch as x variable and boughtAgain as fill and facet variable.)