Date and time functions in R

In library(survival), we can find the following functions:

  • as.date

    Converts any of the following character forms to a Julian date: 8/31/56, 8-31-1956, 31 8 56, 083156, 31Aug56, or August 31 1956.

    Example:

    > as.date(c("1jan1960", "2jan1960", "31mar1960", "30jul1960"))
    [1] 1Jan60  2Jan60  31Mar60 30Jul60
    
  • mdy.date

    Given a month, day, and year, returns the number of days since January 1, 1960.

    Example:

     

    > mdy.date(3, 10, 53)
    [1] 10Mar53
    
  • date.mdy

    Convert a vector of Julian dates to a list of vectors with the corresponding values of month, day and year, and optionally weekday.

    Example:

     

    > a1<-mdy.date(month = 8, day = 7, year = 1960)
    > a1
    [1] 7Aug60
    > date.mdy(a1)
    $month
    [1] 8
    
    $day
    [1] 7
    
    $year
    [1] 1960
    
    > 
    
  • date.mmddyy

    Given a vector of Julian dates, this returns them in the form ``10/11/89'', ``28/7/54'', etc.

    Example:

     

    > date.mmddyy(mdy.date(3, 10, 53))
    [1] "3/10/53"
    
  • date.ddmmmyy

    Given a vector of Julian dates, this returns them in the form ``10Nov89'', ``28Jul54'', etc.

    Example:

     

    > date.ddmmmyy(mdy.date(3, 10, 53))
    [1] "10Mar53"
    
  • date.mmddyyyy

    Given a vector of Julian dates, this returns them in the form ``10/11/1989'', ``28/7/1854'', etc.

    Example:

     

    > date.mmddyyyy(mdy.date(3, 10, 53))
    [1] "3/10/1953"
FAQ Category