R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("chron-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('chron') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "chron" > > ### * chron > > flush(stderr()); flush(stdout()) > > ### Name: chron > ### Title: Create a Chronological Object > ### Aliases: chron as.chron as.chron.default as.chron.POSIXt is.chron > ### as.data.frame.chron format.chron print.chron > ### Keywords: chron > > ### ** 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/92 > # [1] 02/27/92 02/27/92 01/14/92 02/28/92 02/01/92 > tms <- 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:26 > # [1] 23:03:20 22:29:56 01:03:30 18:21:03 16:56:26 > x <- chron(dates = dts, times = tms) > x [1] (02/27/92 23:03:20) (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) > # [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/92 > # [1] 02/27/92 03/08/92 > dts[1] - 31 [1] 01/27/92 > # [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 > # 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/92 > # [1] 02/27/92 02/27/92 02/28/92 02/01/92 > dts > dts[3] [1] TRUE TRUE FALSE TRUE TRUE > # [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/92 > # [1] 01/14/92 02/28/92 > diff(x) Time in days: [1] -0.02319444 -44.89335648 45.72052083 -27.05876157 > # Time in days: > # [1] -0.02319444 -44.89335648 45.72052083 -27.05876157 > sort(dts)[1:3] [1] 01/14/92 02/01/92 02/27/92 > # [1] 01/14/92 02/01/92 02/27/92 > > > > cleanEx(); ..nameEx <- "cut.dates" > > ### * cut.dates > > flush(stderr()); flush(stdout()) > > ### Name: cut.dates > ### Title: Create a Factor from a Chron or Dates Object > ### Aliases: cut.dates > ### Keywords: chron > > ### ** Examples > > # days from 07/01/92 thru 07/15/92 fell into 3 Monday-started weeks > cut(dates("07/01/92") + 0:14, "weeks") [1] week 1 week 1 week 1 week 1 week 1 week 2 week 2 week 2 week 2 week 2 [11] week 2 week 2 week 3 week 3 week 3 Levels: week 1 < week 2 < week 3 > # [1] week 1 week 1 week 1 week 1 week 1 week 2 week 2 week 2 > # [9] week 2 week 2 week 2 week 2 week 3 week 3 week 3 > > dts <- dates(c("02/27/92", "02/27/92", "01/14/92", + "02/28/92", "02/01/92")) > cut(dts, "months") [1] Feb 92 Feb 92 Jan 92 Feb 92 Feb 92 Levels: Jan 92 < Feb 92 > # [1] Feb 92 Feb 92 Jan 92 Feb 92 Feb 92 > boxplot(runif(5) ~ cut(dts, "months")) > > > > cleanEx(); ..nameEx <- "dates" > > ### * dates > > flush(stderr()); flush(stdout()) > > ### Name: dates > ### Title: Generate Dates and Times Components from Input > ### Aliases: dates times Math.dates Ops.dates Summary.dates [<-.dates > ### all.equal.dates as.data.frame.dates c.dates floor.dates format.dates > ### print.dates trunc.dates Math.times Ops.times Summary.times [.times > ### [<-.times [[.times as.character.times as.data.frame.times axis.times > ### c.times diff.times format.times format<-.times hist.times > ### identify.times is.na.times lines.times mean.times plot.times > ### points.times print.times quantile.times summary.times > ### Keywords: chron > > ### ** 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/92 > # [1] 02/27/92 02/27/92 01/14/92 02/28/92 02/01/92 > class(dts) [1] "dates" "times" > > x <- chron(dates = c("02/27/92", "02/27/92", "01/14/92", "02/28/92"), + times = c("23:03:20", "22:29:56", "01:03:30", "18:21:03")) > dates(x) [1] 02/27/92 02/27/92 01/14/92 02/28/92 > # [1] 02/27/92 02/27/92 01/14/92 02/28/92 > > > > cleanEx(); ..nameEx <- "day.of.week" > > ### * day.of.week > > flush(stderr()); flush(stdout()) > > ### Name: day.of.week > ### Title: Convert between Julian and Calendar Dates > ### Aliases: day.of.week julian.default leap.year month.day.year > ### Keywords: chron chron > > ### ** Examples > > julian(1, 1, 1970) [1] 0 > # [1] 0 > unlist(month.day.year(0)) month day year 1 1 1970 > # month day year > # 1 1 1970 > > > > cleanEx(); ..nameEx <- "days" > > ### * days > > flush(stderr()); flush(stdout()) > > ### Name: days > ### Title: Return Various Periods from a Chron or Dates Object > ### Aliases: days months.default quarters.default weekdays.default years > ### Keywords: chron > > ### ** Examples > > dts <- dates("07/01/78") + trunc(50 * rnorm(30)) > plot(weekdays(dts)) > plot(months(dts)) > > > > cleanEx(); ..nameEx <- "hours" > > ### * hours > > flush(stderr()); flush(stdout()) > > ### Name: hours > ### Title: Return Hours, Minutes, or Seconds from a Times Object > ### Aliases: hours minutes seconds > ### Keywords: chron > > ### ** Examples > > x <- chron(dates = c("02/27/92", "02/27/92", "01/14/92", "02/28/92"), + times = c("23:03:20", "22:29:56", "01:03:30", "18:21:03")) > h <- hours(x) > y <- runif(4) > boxplot(y ~ h) > > > > cleanEx(); ..nameEx <- "is.holiday" > > ### * is.holiday > > flush(stderr()); flush(stdout()) > > ### Name: is.holiday > ### Title: Find Weekends and Holidays in a Chron or Dates Object > ### Aliases: is.holiday is.weekend .Holidays > ### Keywords: chron > > ### ** Examples > > dts <- dates("01/01/98") + trunc(365 * runif(50)) > table(is.weekend(dts)) FALSE TRUE 40 10 > > .Holidays New Year's Day Memorial Day Independence Day Labor Day 01/01/92 05/25/92 07/04/92 09/07/92 Thanksgiving Christmas 11/26/92 12/25/92 > # New Year Memorial Indepen. Labor day Thanksgiving Christmas > # 01/01/92 05/25/92 07/04/92 09/07/92 11/26/92 12/25/92 > # NOTE: Only these 6 holidays from 1992 are defined by default! > > > > cleanEx(); ..nameEx <- "seq.dates" > > ### * seq.dates > > flush(stderr()); flush(stdout()) > > ### Name: seq.dates > ### Title: Generate Chron or Dates Sequences > ### Aliases: seq.dates > ### Keywords: chron > > ### ** Examples > > seq.dates("01/01/92", "12/31/92", by = "months") [1] 01/01/92 02/01/92 03/01/92 04/01/92 05/01/92 06/01/92 07/01/92 08/01/92 [9] 09/01/92 10/01/92 11/01/92 12/01/92 > # [1] 01/01/92 02/01/92 03/01/92 04/01/92 05/01/92 06/01/92 > # [7] 07/01/92 08/01/92 09/01/92 10/01/92 11/01/92 12/01/92 > > end.of.the.month <- seq.dates("02/29/92", by = "month", length = 15) > end.of.the.month [1] 02/29/92 03/31/92 04/30/92 05/31/92 06/30/92 07/31/92 08/31/92 09/30/92 [9] 10/31/92 11/30/92 12/31/92 01/31/93 02/28/93 03/31/93 04/30/93 > # [1] 02/29/92 03/31/92 04/30/92 05/31/92 06/30/92 07/31/92 > # [7] 08/31/92 09/30/92 10/31/92 11/30/92 12/31/92 01/31/93 > # [13] 02/28/93 03/31/93 04/30/93 > > > > ### *