Learn R Programming

splusTimeDate (version 1.5.0-72)

days: 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 dates object.
abbreviate
a logical flag. If TRUE, abbreviations should be returned for days of the week, month names, or quarters. Default is TRUE.

Value

  • returns an ordered factor corresponding to days, weekdays, months, quarters, or years of x for the respective function.

Details

  • The levels ofdaysare the days of the month,1through31.
  • The levels ofweekdaysareSundaythroughSaturday.
  • The levels ofmonthsareJanuarythroughDecember.
  • The levels ofquartersare I < II < III < IV ifabb=Fand 1Q < 2Q < 3Q < 4Q ifabbreviate=T.
  • The levels ofyearsare exactly the years of the dates inx. Years in the range ofxthat are not inxitself 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")).

See Also

as.Date, julian, timeDate, hours, yeardays, hms

Examples

Run this code
## 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)

Run the code above in your browser using DataLab