as.month {epitools} | R Documentation |
Convert dates into months of the year for plotting epidemic curves
Description
Converts dates into months of the year (1-12); but also creates range of calendar months that can be used to plot an epidemic curve
Usage
as.month(x, format = "%Y-%m-%d",
min.date, max.date, before = 31, after = 31,
origin = as.Date("1970-01-01"), abbreviate = TRUE)
Arguments
x |
character vector of dates |
format |
date format of |
min.date |
[optional] minimum calendar date for plotting x-axis of an epidemic
curve; should be of the form of "2004-08-10"; if no date is
specified, then several days are subtracted from the minimum date in
|
max.date |
[optional] maximum calendar date for plotting x-axis of an epidemic
curve plot; should be f the form of "2004-08-10"; if no date is
specified, then several days are added to the maximum date in
|
before |
if |
after |
if |
origin |
allows user to specify an alternative origin for Julian dates that are generated by this function (default = "1970-01-01") |
abbreviate |
abbreviate month names to Jan, Feb, Mar, etc.; often used for labeling plots |
Details
This function converts dates to months (1-12). In addition, a range of calendar months are generated that can be used to plot the x-axis of an epidemic curve.
Value
Returns a list of the following:
$dates |
input dates are converted to standard calendar date format |
$mon |
month of the year (1-12) |
$month |
month of the year (Jan, Feb, Mar, ...) |
$stratum |
the Julian date for the mid-month day of the |
$stratum2 |
the Julian date for the mid-month day of the |
$stratum3 |
the mid-month day of the |
$cmon |
the month of the year (1-12) used for plotting the x-axis of the epidemic curve |
$cmonth |
the months (Jan, Feb, Mar, ...) for the calendar dates used for plotting the x-axis of an epidemic curve |
$cstratum |
the Julian date for the mid-month day of the |
$cstratum2 |
the standard calendar date for the mid-month day of the
|
$cmday |
the day of the mon (1-31) for the calendar dates used for plotting the x-axis of an epidemic curve |
$cyear |
the years (e.g., 1996, 2001, ...) for the calendar dates used for plotting the x-axis of the epidemic curve |
Author(s)
Tomas Aragon, aragon@berkeley.edu, http://www.phdata.science
References
none
See Also
epitools: as.week
, epicurve.dates
as.Date
, strptime
,
DateTimeClasses
Examples
dates <- c("1/1/04", "1/2/04", "1/3/04", "1/4/04", "1/5/04", "1/6/04",
"1/7/04", "1/8/04", "1/9/04", "1/10/04", NA, "1/12/04", "1/14/04",
"3/5/04", "5/5/04", "7/6/04", "8/18/04", "12/13/05", "1/5/05",
"4/6/05", "7/23/05", "10/3/05")
aw <- as.month(dates, format = "%m/%d/%y")
aw
aw2 <- as.month(dates, format = "%m/%d/%y", min.date="2003-01-01")
aw2