Learn R Programming

epitools (version 0.5-2)

as.hour: Convert date-time object into hour units

Description

Convert date-time object into hour or half-hour units

Usage

as.hour(x, mindt, maxdt, half.hour = FALSE)

Arguments

x
Date-time object in standard format: for example, "2004-12-23 08:27:00", "2004-12-23 08:27", "2004-12-23"
mindt
[required] Date-time object in standard format that will form the lower boundary of the hour or half-hour time categories. mindt must less than or equal to the minimum value in x, and must be rounded off to the nearst hour for
maxdt
[required] Date-time object in standard format that will form the upper boundary of the hour or half-hour time categories. maxdt must greater than or equal to the minimum value in x, and must be rounded off to the nearst hour
half.hour
Set to TRUE for half-hour categories.

Value

  • $ctDate-time object that contains the number of seconds since the beginning of 1970 as a numeric vector and produced by as.POSIXct. You can use as.POSIXlt to convert this output in human legible (already done by this function).
  • $secseconds
  • $minminutes
  • $hourhours (0-23)
  • $hour12hours (1-12)
  • $stratumnumber of hours or 1/2 hours since beginning of 1970
  • $stratum2factor (categorical variable) with number of hours of 1/2 hours since beginning of 1970 using $cstratum as the levels
  • $stratum3factor (categorical variable) in standard date-time format indicating number of hours or 1/2 hours since beginning of 1970 using $cstratum2 as the levels
  • $cstratumlevels for creating $stratum2 factor
  • $cstratum2levels for creating $stratum3 factor
  • $csecseconds from $cstratum2
  • $cminminutes from $cstratum2
  • $chourhours from $cstratum2 in 24-hour format
  • $chour12hours from $cstratum2 in 12-hour format
  • $campmcorresponding 'AM' or 'PM' for $chour12
  • $campm2corresponding 'am' or 'pm' for $chour12
  • $cweekdayday of the week for $cstratum2
  • $cwkdayabbreviated day of the week for $cstratum2
  • $cmdayday of the month for $cstratum2
  • $cmonthmonth for $cstratum2
  • $cmonabbreviated month for $cstratum2
  • $cyearyear for $cstratum2
  • $half.hourFALSE (default) for 1-hour categories; TRUE for 1/2-hour categories

Details

This function (1) converts standard date-time objects into 1-hour or 1/2-hour categories, and (2) generates levels for range of values that that the new 1-hour or 1/2-hour categories can take. These levels are use for converting x into a factor and for providing names for labeling the x-axis in plot. This function is used by epicurves.hours.

References

none

See Also

epitools: as.month, epicurve.dates as.Date, strptime, DateTimeClasses

Examples

Run this code
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.week(dates, format = "%m/%d/%y")
aw

aw2 <- as.week(dates, format = "%m/%d/%y", sunday= FALSE)
aw2

aw3 <- as.week(dates, format = "%m/%d/%y", min.date="2003-01-01")
aw3

Run the code above in your browser using DataLab