days {splusTimeDate} | R Documentation |
Return Various Periods from a Time or Date Object
Description
Creates an ordered factor from a vector of dates according to various calendar periods.
Usage
days(x)
weekdays(x, abbreviate = TRUE)
months(x, abbreviate = TRUE)
quarters(x, abbreviate = TRUE)
years(x)
Arguments
x |
a |
abbreviate |
a logical flag. If |
Details
The levels of
days
are the days of the month,1
through31
.The levels of
weekdays
areSunday
throughSaturday
.The levels of
months
areJanuary
throughDecember
.The levels of
quarters
are I < II < III < IV ifabb=F
and 1Q < 2Q < 3Q < 4Q ifabbreviate=T
.The levels of
years
are exactly the years of the dates inx
. Years in the range ofx
that are not inx
itself are not interpolated.
These functions are generic.
The default method works on dates
objects
and other objects that can be coerced to dates
objects.
There are also methods for timeDate
, which take weekday and month names
and abbreviations from timeDateOptions(c("time.day.name",
"time.day.abb", "time.month.name", "time.month.abb"))
.
Value
returns an ordered factor corresponding to days, weekdays, months,
quarters, or years of x
for the respective function.
See Also
as.Date
, julian
,
timeDate
, hours
, yeardays
,
hms
Examples
## Creates a sample dates object of julian dates
x <- c(10, 11, 12, 42, 44, 45, 101, 102, 212, 213, 214, 300)
dts <- as.Date(x, origin="1960-1-1")
## Alternatively, create a sample timeDate object
dts <- as(x, "timeDate")
## identifies a weekday or month with each julian day
weekdays(dts)
months(dts)
## Produces barplot of # of days in x appearing on particular
## weekday or month
plot(weekdays(dts))
plot(months(dts))
## Produces boxplots of julian date by weekday or month
plot(weekdays(dts), x)
plot(months(dts), x)