Blame | Last modification | View Log | Download | RSS feed
\name{chron}\alias{chron}\alias{as.chron}\alias{as.chron.default}\alias{as.chron.POSIXt}\alias{is.chron}\alias{as.data.frame.chron}\alias{format.chron}\alias{print.chron}\title{Create a Chronological Object}\description{Create chrononogical objects which represent dates and times of day.}\usage{chron(dates., times., format = c(dates = "m/d/y", times = "h:m:s"),out.format, origin.)}\arguments{\item{dates.}{character or numeric vector specifying dates. Ifcharacter, \code{dates.} are assumed to be in one of the dateformats below; if numeric, \code{dates.} are assumed to be Juliandates, i.e., number of days since \code{origin.}.}\item{times.}{optional character or numeric vector specifying times ofday. If character, \code{times.} are assumed to be in one of thetime formats below; if numeric, \code{times.} are assumed to befractions of a day.}\item{format}{vector or list specifying the input format of the input.The format can be either strings specifying one of the recognizedformats below or a list of user-supplied functions to convert datesfrom character into Julian dates and vice versa.The dates format can be any permutation of the characters\code{"d"}, \code{"m"}, or \code{"y"} delimited by a separator(possibly null), e.g., \code{"m/d/y"}, \code{"d-m-y"}, \code{"ymd"},are all valid; the format can also be permutations of the words\code{"day"}, \code{"month"} and \code{"year"} (with non-nullseparator), which produces the month name, e.g., \code{"month dayyear"} produces \code{"April 20 1992"}, \code{"day mon year"}produces \code{"20 Apr 1992"}.The times format can be any permutation of \code{"h"}, \code{"m"},and \code{"s"} separated by any one non-special character. Thedefault is \code{"h:m:s"}.}\item{out.format}{vector or list specifying date and time format forprinting and output. Default is same as \code{format}.}\item{origin.}{a vector specifying the date with respect to whichJulian dates are computed. Default is\code{c(month = 1, day = 1, year = 1970)};you may set the option \code{chron.origin} to specify your owndefault, e.g.,\code{options(chron.origin = c(month=1, day=1, year=1990))}.}}\value{An object of class \code{"times"} if only \code{times.} werespecified, \code{"dates"} if only \code{dates.}, or \code{"chron"} ifboth \code{dates.} and \code{times.} were supplied. All these inheritfrom class \code{"times"}.These objects represent dates and times of day, and allow thefollowing arithmetic and summaries: subtraction \code{d1-d2},constant addition \code{d1+constants}, all logical comparisons,summaries \code{min()}, \code{max()}, and \code{range()} (which dropNAs by default); constants specify days (fractions are converted totime-of-day, e.g., 2.5 represents 2 days and 12 hours). Operationssuch as sorting, differencing, etc., are automatically handled.There are methods for \code{as.character()}, \code{as.numeric()},\code{cut()}, \code{is.na()}, \code{print()}, \code{summary()},\code{plot()}, \code{lines()}, \code{lag()}, and the usual subsettingfunctions \code{[}, \code{[<-}.The functions \code{days()}, \code{months()}, \code{quarters()},\code{years()}, \code{weeks()}, \code{weekdays()}, \code{hours()},\code{minutes()}, and \code{seconds()} take any \code{chron} object asinput and extract the corresponding time interval.\code{cut()} is used to create ordered factors from \code{chron}objects. Chronological objects may be used with the modeling software.The current implementation of \code{chron} objects does not handletime zones nor daylight savings time.}\seealso{\code{\link{dates}},\code{\link{times}},\code{\link{julian.default}},\code{\link{cut.dates}},\code{\link{seq.dates}}.}\examples{dts <- dates(c("02/27/92", "02/27/92", "01/14/92","02/28/92", "02/01/92"))dts# [1] 02/27/92 02/27/92 01/14/92 02/28/92 02/01/92tms <- times(c("23:03:20", "22:29:56", "01:03:30","18:21:03", "16:56:26"))tms# [1] 23:03:20 22:29:56 01:03:30 18:21:03 16:56:26x <- chron(dates = dts, times = tms)x# [1] (02/27/92 23:03:19) (02/27/92 22:29:56) (01/14/92 01:03:30)# [4] (02/28/92 18:21:03) (02/01/92 16:56:26)# We can add or subtract scalars (representing days) to dates or# chron objects:c(dts[1], dts[1] + 10)# [1] 02/27/92 03/08/92dts[1] - 31# [1] 01/27/92# We can substract dates which results in a times object that# represents days between the operands:dts[1] - dts[3]# Time in days:# [1] 44# Logical comparisons work as expected:dts[dts > "01/25/92"]# [1] 02/27/92 02/27/92 02/28/92 02/01/92dts > dts[3]# [1] TRUE TRUE FALSE TRUE TRUE# Summary operations which are sensible are permitted and work as# expected:range(dts)# [1] 01/14/92 02/28/92diff(x)# Time in days:# [1] -0.02319444 -44.89335648 45.72052083 -27.05876157sort(dts)[1:3]# [1] 01/14/92 02/01/92 02/27/92}% Converted by Sd2Rd version 0.2-a3.\keyword{chron}