Learn R Programming

epitools (version 0.5-2)

epidate: Convert dates into multiple legible formats

Description

Convert character vector of dates into multiple legible formats.

Usage

epidate(x, format = "%m/%d/%Y", cal.dates = FALSE,
        before = 7, after = 7, sunday = TRUE)

Arguments

x
character vector of dates to be converted
format
format of character vector of dates
cal.dates
Calendar dates that contains x, starting 7 days 'before' (default) until 7 days 'after' x
before
defines lower limit of cal.dates: default is 7 days before earliest date in x
after
defines upper limit of cal.dates: default is 7 days after latest date in x
sunday
first day of the week is either Sunday (default) or Monday

Value

  • datesdates wtih date-time class
  • juliannumber of days since 1970-01-01
  • mdayday of the month: 1-31
  • monmonth of the year: 0-11
  • monthmonth: January, February, March, ...
  • month2month: Jan, Feb, Mar, ...
  • firstdayfirst day of the week: Sunday or Monday
  • weekweek of the year: 0-53
  • yearyear: YYYY
  • yryear: YY
  • wdayday of the week: 0-6
  • weekdayweekday: Monday, Tuesday, Wednesday, ...
  • wkdayweekday: Mon, Tue, Wed, ...
  • ydayday of the year: 0-365
  • quarterquarter of the year: Q1, Q2, Q3, Q4
  • cdatesCalendar dates that contains dates
  • cjulianJulian calendar dates

Details

Dates can come in many formats (e.g., November 12, 2001, 12Nov01, 11/12/2001, 11/12/01, 2001-11-12) and need to be converted into other formats for data analysis, graphical displays, generating reports, etc. There is tremendous flexibility in converting any character vector with sufficient information to be converted into a unique date. For complete options for the format option see strptime.

References

none

See Also

epitools: as.week DateTimeClasses to learn about date-time classes as.Date to convert character vector of dates into calendar dates with date-time class (done by epidate) strptime to convert date-time character strings into a date-time class format.POSIXlt or format.POSIXlt to convert date-time classes into character representations as.POSIXlt to convert either date-time objects or date-time character strings into a human legible date-time class (done by epidate) as.POSIXct to convert either date-time objects or date-time character strings into a continuous time date-time class (not done by epidate) weekdays, months, quarters, or julian, to convert date-time objects into weekdays, months, quarters, or julian representations, respectively (all are done by epidate)

Examples

Run this code
#x <- c("12/1/03", "11/2/03", NA, "1/7/04", "1/14/04", "8/18/04")
#epidate(x, format = "\%m/\%d/\%y")
#epidate(x, format = "\%m/\%d/\%y", TRUE)
#
###convert vector of disease weeks into vector of mid-week dates
#dwk <- sample(0:53, 100, replace = TRUE)
#wk2date <- paste(dwk, "/", "Wed", sep="")
#wk2date[1:10]
#wk2date2 <- epidate(wk2date, format = "\%U/\%a")
#wk2date2$dates[1:20]

Run the code above in your browser using DataLab