10.11 Dates in R

10.11.1 Converting dates to survival time

In the melanoma example dataset, we already had the time in a convenient format for survival analysis - survival time in days since the operation. This section shows how to convert dates into “days from event”. First we will generate a dummy operation date and censoring date based on the melanoma data.

Now we will to create a ‘censoring’ date by adding time from the melanoma dataset to our made up operation date.

Remember the censoring date is either when an event occurred (e.g. death) or the last known alive status of the patient.

Now consider if we only had the operation date and censoring date. We want to create the time variable.

The Surv() function expects a number (numeric variable), rather than a date object, so we’ll convert it: