dateStem | R Documentation |
For a sequence of POSIXct or POSIXt date/times, return a string summarizing the constant portion of the range; ie. that shared among all dates. The main purpose of this is to provide additional information for xyplot()s that don't have enough detail on the time axis to let you know what period of time you're looking at. For this reason, one extra component is included when dates cross a unit boundary, but span less than a unit; e.g. if the date range goes overnight, but isn't a full day in size.
dateStem(dates, formats = c("", "%Y", "%Y %b", "%Y %b %d",
"%Y %b %d, %I %p", "%Y %b %d, %I:%M %p",
"%Y %b %d, %I:%M:%S %p"))
dates |
vector of POSIXct or POSIXt date/times |
formats |
character vector; formatting strings compatible with
|
character scalar; this is earliest element of dates
,
formatted with the n
-th element of formats
, where
$coden is the index of the first date/time component that
varies among dates
; i.e.:
n=1
if the year varies among dates
n=2
if the year is constant but the month varies
n=3
if the year and month are constant but the day varies
etc.
If length(formats) < n
, the last element of formats
is used.
This function is intended for use in labelling time axes in plots
generated by lattice::xyplot()
when the latter does not
display enough information to fully determine the displayed
date/time.
It probably makes more sense to just add
paste(format(range(..$ts)), collapse=" to ")
to the time
axis label...
John Brzustowski jbrzusto@REMOVE_THIS_PART_fastmail.fm
library(lubridate)
dateStem(ymd("2013-05-01", "2014-06-15")) ## returns ""
dateStem(ymd("2014-05-01", "2014-06-15")) ## returns "2014"
dateStem(ymd("2014-05-01", "2014-05-10")) ## returns "2014 May"
dateStem(ymd_hms("2014-05-01 03:20:17", "2014-05-01 21:09:32")) ## returns "2014 May 1"
dateStem(ymd_hms("2014-05-01 03:20:17", "2014-05-01 03:09:32")) ## returns "2014 May 1, 03 AM"
dateStem(ymd_hms("2014-05-01 03:20:17", "2014-05-01 03:20:32")) ## returns "2014 May 1, 03:20 AM"
dateStem(ymd_hms("2014-05-01 03:20:17", "2014-05-01 03:20:17")) ## returns "2014 May 1, 03:20:17 AM"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.