as.hour {epitools}R Documentation

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 hour categories (e.g., HH:00:00) or rounded off to the nearest half-hour for half-hour categories (e.g., HH:30:00).

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 for hour categories (e.g., HH:00:00) or rounded off to the nearest half-hour for half-hour categories (e.g., HH:30:00).

half.hour

Set to TRUE for half-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.

Value

$ct

Date-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).

$sec

seconds

$min

minutes

$hour

hours (0-23)

$hour12

hours (1-12)

$stratum

number of hours or 1/2 hours since beginning of 1970

$stratum2

factor (categorical variable) with number of hours of 1/2 hours since beginning of 1970 using $cstratum as the levels

$stratum3

factor (categorical variable) in standard date-time format indicating number of hours or 1/2 hours since beginning of 1970 using $cstratum2 as the levels

$cstratum

levels for creating $stratum2 factor

$cstratum2

levels for creating $stratum3 factor

$csec

seconds from $cstratum2

$cmin

minutes from $cstratum2

$chour

hours from $cstratum2 in 24-hour format

$chour12

hours from $cstratum2 in 12-hour format

$campm

corresponding 'AM' or 'PM' for $chour12

$campm2

corresponding 'am' or 'pm' for $chour12

$cweekday

day of the week for $cstratum2

$cwkday

abbreviated day of the week for $cstratum2

$cmday

day of the month for $cstratum2

$cmonth

month for $cstratum2

$cmon

abbreviated month for $cstratum2

$cyear

year for $cstratum2

$half.hour

FALSE (default) for 1-hour categories; TRUE for 1/2-hour categories

Author(s)

Tomas Aragon, aragon@berkeley.edu, http://www.phdata.science

References

none

See Also

epitools: as.month, 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.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


[Package epitools version 0.5-10.1 Index]