Search code examples
rtimesurvival-analysissurvival

Convert numeric (days) to numeric (months) in R


How do I convert a list of survival times for patients in days to months in R? I would like to perform the survival analysis such as KM curve using months instead of days.

The raw dataset comes in days. For example, Patient 1 - 500, Patient 2 - 450, Patient 3 - 600 etc. There are no units (only numerals) and similarly I would like numerals in months.

Thanks in advance for your help.


Solution

  • # load package
    library(dplyr)
    
    # example dataframe
    patient = c(1,2,3)
    days = c(500, 450, 600)
    df <- as.data.frame(cbind(patient, days))
    
    # calculate month
    df <- df %>% 
      mutate(month = round(days/30.417, digit=0))
    
    # show dataframe
    View(df)