These functions can be used to convert the times of "ts" series with frequency of 12 or 4 or objects of "yearmon" and "yearqtr" class, as defined in the "zoo" package, to chron dates.

# S3 method for class 'yearmon'
as.chron(x, frac = 0, holidays = FALSE, ...)
# S3 method for class 'yearqtr'
as.chron(x, frac = 0, holidays = FALSE, ...)
# S3 method for class 'ts'
as.chron(x, frac = 0, holidays = FALSE, ...)

Arguments

x

an object of class "yearmon" or "yearqtr" or "ts" objects, or a numeric vector interpreted “in years” and fractions of years.

frac

Number between zero and one inclusive representing the fraction of the way through the month or quarter.

holidays

If TRUE or a vector of chron dates, indicated holidays and weekends are excluded so the return value will be a non-holiday weekday.

...

Other arguments passed to chron.

Details

The "yearmon" and "yearqtr" classes are defined in package zoo. If holidays is TRUE or a vector of dates then the is.holiday function is used to determine whether days are holidays.

The method for ts objects converts the times corresponding to time(x) to chron. The ts series must have a frequency that is a divisor of 12.

Value

Returns a chron object.

See also

Examples

## Monthly time series data.
as.chron(AirPassengers)
#>   [1] 01/01/49 02/01/49 03/01/49 04/01/49 05/01/49 06/01/49 07/01/49 08/01/49
#>   [9] 09/01/49 10/01/49 11/01/49 12/01/49 01/01/50 02/01/50 03/01/50 04/01/50
#>  [17] 05/01/50 06/01/50 07/01/50 08/01/50 09/01/50 10/01/50 11/01/50 12/01/50
#>  [25] 01/01/51 02/01/51 03/01/51 04/01/51 05/01/51 06/01/51 07/01/51 08/01/51
#>  [33] 09/01/51 10/01/51 11/01/51 12/01/51 01/01/52 02/01/52 03/01/52 04/01/52
#>  [41] 05/01/52 06/01/52 07/01/52 08/01/52 09/01/52 10/01/52 11/01/52 12/01/52
#>  [49] 01/01/53 02/01/53 03/01/53 04/01/53 05/01/53 06/01/53 07/01/53 08/01/53
#>  [57] 09/01/53 10/01/53 11/01/53 12/01/53 01/01/54 02/01/54 03/01/54 04/01/54
#>  [65] 05/01/54 06/01/54 07/01/54 08/01/54 09/01/54 10/01/54 11/01/54 12/01/54
#>  [73] 01/01/55 02/01/55 03/01/55 04/01/55 05/01/55 06/01/55 07/01/55 08/01/55
#>  [81] 09/01/55 10/01/55 11/01/55 12/01/55 01/01/56 02/01/56 03/01/56 04/01/56
#>  [89] 05/01/56 06/01/56 07/01/56 08/01/56 09/01/56 10/01/56 11/01/56 12/01/56
#>  [97] 01/01/57 02/01/57 03/01/57 04/01/57 05/01/57 06/01/57 07/01/57 08/01/57
#> [105] 09/01/57 10/01/57 11/01/57 12/01/57 01/01/58 02/01/58 03/01/58 04/01/58
#> [113] 05/01/58 06/01/58 07/01/58 08/01/58 09/01/58 10/01/58 11/01/58 12/01/58
#> [121] 01/01/59 02/01/59 03/01/59 04/01/59 05/01/59 06/01/59 07/01/59 08/01/59
#> [129] 09/01/59 10/01/59 11/01/59 12/01/59 01/01/60 02/01/60 03/01/60 04/01/60
#> [137] 05/01/60 06/01/60 07/01/60 08/01/60 09/01/60 10/01/60 11/01/60 12/01/60
as.chron(time(AirPassengers))
#>   [1] 01/01/49 02/01/49 03/01/49 04/01/49 05/01/49 06/01/49 07/01/49 08/01/49
#>   [9] 09/01/49 10/01/49 11/01/49 12/01/49 01/01/50 02/01/50 03/01/50 04/01/50
#>  [17] 05/01/50 06/01/50 07/01/50 08/01/50 09/01/50 10/01/50 11/01/50 12/01/50
#>  [25] 01/01/51 02/01/51 03/01/51 04/01/51 05/01/51 06/01/51 07/01/51 08/01/51
#>  [33] 09/01/51 10/01/51 11/01/51 12/01/51 01/01/52 02/01/52 03/01/52 04/01/52
#>  [41] 05/01/52 06/01/52 07/01/52 08/01/52 09/01/52 10/01/52 11/01/52 12/01/52
#>  [49] 01/01/53 02/01/53 03/01/53 04/01/53 05/01/53 06/01/53 07/01/53 08/01/53
#>  [57] 09/01/53 10/01/53 11/01/53 12/01/53 01/01/54 02/01/54 03/01/54 04/01/54
#>  [65] 05/01/54 06/01/54 07/01/54 08/01/54 09/01/54 10/01/54 11/01/54 12/01/54
#>  [73] 01/01/55 02/01/55 03/01/55 04/01/55 05/01/55 06/01/55 07/01/55 08/01/55
#>  [81] 09/01/55 10/01/55 11/01/55 12/01/55 01/01/56 02/01/56 03/01/56 04/01/56
#>  [89] 05/01/56 06/01/56 07/01/56 08/01/56 09/01/56 10/01/56 11/01/56 12/01/56
#>  [97] 01/01/57 02/01/57 03/01/57 04/01/57 05/01/57 06/01/57 07/01/57 08/01/57
#> [105] 09/01/57 10/01/57 11/01/57 12/01/57 01/01/58 02/01/58 03/01/58 04/01/58
#> [113] 05/01/58 06/01/58 07/01/58 08/01/58 09/01/58 10/01/58 11/01/58 12/01/58
#> [121] 01/01/59 02/01/59 03/01/59 04/01/59 05/01/59 06/01/59 07/01/59 08/01/59
#> [129] 09/01/59 10/01/59 11/01/59 12/01/59 01/01/60 02/01/60 03/01/60 04/01/60
#> [137] 05/01/60 06/01/60 07/01/60 08/01/60 09/01/60 10/01/60 11/01/60 12/01/60
## convert to first day of the month that is not a weekend or holiday
as.chron(AirPassengers, frac = 0, holidays = TRUE)
#>   [1] 01/03/49 02/01/49 03/01/49 04/01/49 05/02/49 06/01/49 07/01/49 08/01/49
#>   [9] 09/01/49 10/03/49 11/01/49 12/01/49 01/02/50 02/01/50 03/01/50 04/03/50
#>  [17] 05/01/50 06/01/50 07/03/50 08/01/50 09/01/50 10/02/50 11/01/50 12/01/50
#>  [25] 01/01/51 02/01/51 03/01/51 04/02/51 05/01/51 06/01/51 07/02/51 08/01/51
#>  [33] 09/03/51 10/01/51 11/01/51 12/03/51 01/01/52 02/01/52 03/03/52 04/01/52
#>  [41] 05/01/52 06/02/52 07/01/52 08/01/52 09/01/52 10/01/52 11/03/52 12/01/52
#>  [49] 01/01/53 02/02/53 03/02/53 04/01/53 05/01/53 06/01/53 07/01/53 08/03/53
#>  [57] 09/01/53 10/01/53 11/02/53 12/01/53 01/01/54 02/01/54 03/01/54 04/01/54
#>  [65] 05/03/54 06/01/54 07/01/54 08/02/54 09/01/54 10/01/54 11/01/54 12/01/54
#>  [73] 01/03/55 02/01/55 03/01/55 04/01/55 05/02/55 06/01/55 07/01/55 08/01/55
#>  [81] 09/01/55 10/03/55 11/01/55 12/01/55 01/02/56 02/01/56 03/01/56 04/02/56
#>  [89] 05/01/56 06/01/56 07/02/56 08/01/56 09/03/56 10/01/56 11/01/56 12/03/56
#>  [97] 01/01/57 02/01/57 03/01/57 04/01/57 05/01/57 06/03/57 07/01/57 08/01/57
#> [105] 09/02/57 10/01/57 11/01/57 12/02/57 01/01/58 02/03/58 03/03/58 04/01/58
#> [113] 05/01/58 06/02/58 07/01/58 08/01/58 09/01/58 10/01/58 11/03/58 12/01/58
#> [121] 01/01/59 02/02/59 03/02/59 04/01/59 05/01/59 06/01/59 07/01/59 08/03/59
#> [129] 09/01/59 10/01/59 11/02/59 12/01/59 01/01/60 02/01/60 03/01/60 04/01/60
#> [137] 05/02/60 06/01/60 07/01/60 08/01/60 09/01/60 10/03/60 11/01/60 12/01/60
## convert to last day of the month
as.chron(AirPassengers, frac = 1)
#>   [1] 01/31/49 02/28/49 03/31/49 04/30/49 05/31/49 06/30/49 07/31/49 08/31/49
#>   [9] 09/30/49 10/31/49 11/30/49 12/31/49 01/31/50 02/28/50 03/31/50 04/30/50
#>  [17] 05/31/50 06/30/50 07/31/50 08/31/50 09/30/50 10/31/50 11/30/50 12/31/50
#>  [25] 01/31/51 02/28/51 03/31/51 04/30/51 05/31/51 06/30/51 07/31/51 08/31/51
#>  [33] 09/30/51 10/31/51 11/30/51 12/31/51 01/31/52 02/29/52 03/31/52 04/30/52
#>  [41] 05/31/52 06/30/52 07/31/52 08/31/52 09/30/52 10/31/52 11/30/52 12/31/52
#>  [49] 01/31/53 02/28/53 03/31/53 04/30/53 05/31/53 06/30/53 07/31/53 08/31/53
#>  [57] 09/30/53 10/31/53 11/30/53 12/31/53 01/31/54 02/28/54 03/31/54 04/30/54
#>  [65] 05/31/54 06/30/54 07/31/54 08/31/54 09/30/54 10/31/54 11/30/54 12/31/54
#>  [73] 01/31/55 02/28/55 03/31/55 04/30/55 05/31/55 06/30/55 07/31/55 08/31/55
#>  [81] 09/30/55 10/31/55 11/30/55 12/31/55 01/31/56 02/29/56 03/31/56 04/30/56
#>  [89] 05/31/56 06/30/56 07/31/56 08/31/56 09/30/56 10/31/56 11/30/56 12/31/56
#>  [97] 01/31/57 02/28/57 03/31/57 04/30/57 05/31/57 06/30/57 07/31/57 08/31/57
#> [105] 09/30/57 10/31/57 11/30/57 12/31/57 01/31/58 02/28/58 03/31/58 04/30/58
#> [113] 05/31/58 06/30/58 07/31/58 08/31/58 09/30/58 10/31/58 11/30/58 12/31/58
#> [121] 01/31/59 02/28/59 03/31/59 04/30/59 05/31/59 06/30/59 07/31/59 08/31/59
#> [129] 09/30/59 10/31/59 11/30/59 12/31/59 01/31/60 02/29/60 03/31/60 04/30/60
#> [137] 05/31/60 06/30/60 07/31/60 08/31/60 09/30/60 10/31/60 11/30/60 12/31/60
## convert to last day of the month that is not a weekend or holiday
as.chron(AirPassengers, frac = 1, holidays = TRUE)
#>   [1] 01/31/49 02/28/49 03/31/49 04/29/49 05/31/49 06/30/49 07/29/49 08/31/49
#>   [9] 09/30/49 10/31/49 11/30/49 12/30/49 01/31/50 02/28/50 03/31/50 04/28/50
#>  [17] 05/31/50 06/30/50 07/31/50 08/31/50 09/29/50 10/31/50 11/30/50 12/29/50
#>  [25] 01/31/51 02/28/51 03/30/51 04/30/51 05/31/51 06/29/51 07/31/51 08/31/51
#>  [33] 09/28/51 10/31/51 11/30/51 12/31/51 01/31/52 02/29/52 03/31/52 04/30/52
#>  [41] 05/30/52 06/30/52 07/31/52 08/29/52 09/30/52 10/31/52 11/28/52 12/31/52
#>  [49] 01/30/53 02/27/53 03/31/53 04/30/53 05/29/53 06/30/53 07/31/53 08/31/53
#>  [57] 09/30/53 10/30/53 11/30/53 12/31/53 01/29/54 02/26/54 03/31/54 04/30/54
#>  [65] 05/31/54 06/30/54 07/30/54 08/31/54 09/30/54 10/29/54 11/30/54 12/31/54
#>  [73] 01/31/55 02/28/55 03/31/55 04/29/55 05/31/55 06/30/55 07/29/55 08/31/55
#>  [81] 09/30/55 10/31/55 11/30/55 12/30/55 01/31/56 02/29/56 03/30/56 04/30/56
#>  [89] 05/31/56 06/29/56 07/31/56 08/31/56 09/28/56 10/31/56 11/30/56 12/31/56
#>  [97] 01/31/57 02/28/57 03/29/57 04/30/57 05/31/57 06/28/57 07/31/57 08/30/57
#> [105] 09/30/57 10/31/57 11/29/57 12/31/57 01/31/58 02/28/58 03/31/58 04/30/58
#> [113] 05/30/58 06/30/58 07/31/58 08/29/58 09/30/58 10/31/58 11/28/58 12/31/58
#> [121] 01/30/59 02/27/59 03/31/59 04/30/59 05/29/59 06/30/59 07/31/59 08/31/59
#> [129] 09/30/59 10/30/59 11/30/59 12/31/59 01/29/60 02/29/60 03/31/60 04/29/60
#> [137] 05/31/60 06/30/60 07/29/60 08/31/60 09/30/60 10/31/60 11/30/60 12/30/60
## convert to last weekday of the month
as.chron(AirPassengers, frac = 1, holidays = c())
#>   [1] 01/31/49 02/28/49 03/31/49 04/29/49 05/31/49 06/30/49 07/29/49 08/31/49
#>   [9] 09/30/49 10/31/49 11/30/49 12/30/49 01/31/50 02/28/50 03/31/50 04/28/50
#>  [17] 05/31/50 06/30/50 07/31/50 08/31/50 09/29/50 10/31/50 11/30/50 12/29/50
#>  [25] 01/31/51 02/28/51 03/30/51 04/30/51 05/31/51 06/29/51 07/31/51 08/31/51
#>  [33] 09/28/51 10/31/51 11/30/51 12/31/51 01/31/52 02/29/52 03/31/52 04/30/52
#>  [41] 05/30/52 06/30/52 07/31/52 08/29/52 09/30/52 10/31/52 11/28/52 12/31/52
#>  [49] 01/30/53 02/27/53 03/31/53 04/30/53 05/29/53 06/30/53 07/31/53 08/31/53
#>  [57] 09/30/53 10/30/53 11/30/53 12/31/53 01/29/54 02/26/54 03/31/54 04/30/54
#>  [65] 05/31/54 06/30/54 07/30/54 08/31/54 09/30/54 10/29/54 11/30/54 12/31/54
#>  [73] 01/31/55 02/28/55 03/31/55 04/29/55 05/31/55 06/30/55 07/29/55 08/31/55
#>  [81] 09/30/55 10/31/55 11/30/55 12/30/55 01/31/56 02/29/56 03/30/56 04/30/56
#>  [89] 05/31/56 06/29/56 07/31/56 08/31/56 09/28/56 10/31/56 11/30/56 12/31/56
#>  [97] 01/31/57 02/28/57 03/29/57 04/30/57 05/31/57 06/28/57 07/31/57 08/30/57
#> [105] 09/30/57 10/31/57 11/29/57 12/31/57 01/31/58 02/28/58 03/31/58 04/30/58
#> [113] 05/30/58 06/30/58 07/31/58 08/29/58 09/30/58 10/31/58 11/28/58 12/31/58
#> [121] 01/30/59 02/27/59 03/31/59 04/30/59 05/29/59 06/30/59 07/31/59 08/31/59
#> [129] 09/30/59 10/30/59 11/30/59 12/31/59 01/29/60 02/29/60 03/31/60 04/29/60
#> [137] 05/31/60 06/30/60 07/29/60 08/31/60 09/30/60 10/31/60 11/30/60 12/30/60

## Quarterly time series data.
as.chron(presidents)
#>   [1] 01/01/45 04/01/45 07/01/45 10/01/45 01/01/46 04/01/46 07/01/46 10/01/46
#>   [9] 01/01/47 04/01/47 07/01/47 10/01/47 01/01/48 04/01/48 07/01/48 10/01/48
#>  [17] 01/01/49 04/01/49 07/01/49 10/01/49 01/01/50 04/01/50 07/01/50 10/01/50
#>  [25] 01/01/51 04/01/51 07/01/51 10/01/51 01/01/52 04/01/52 07/01/52 10/01/52
#>  [33] 01/01/53 04/01/53 07/01/53 10/01/53 01/01/54 04/01/54 07/01/54 10/01/54
#>  [41] 01/01/55 04/01/55 07/01/55 10/01/55 01/01/56 04/01/56 07/01/56 10/01/56
#>  [49] 01/01/57 04/01/57 07/01/57 10/01/57 01/01/58 04/01/58 07/01/58 10/01/58
#>  [57] 01/01/59 04/01/59 07/01/59 10/01/59 01/01/60 04/01/60 07/01/60 10/01/60
#>  [65] 01/01/61 04/01/61 07/01/61 10/01/61 01/01/62 04/01/62 07/01/62 10/01/62
#>  [73] 01/01/63 04/01/63 07/01/63 10/01/63 01/01/64 04/01/64 07/01/64 10/01/64
#>  [81] 01/01/65 04/01/65 07/01/65 10/01/65 01/01/66 04/01/66 07/01/66 10/01/66
#>  [89] 01/01/67 04/01/67 07/01/67 10/01/67 01/01/68 04/01/68 07/01/68 10/01/68
#>  [97] 01/01/69 04/01/69 07/01/69 10/01/69 01/01/70 04/01/70 07/01/70 10/01/70
#> [105] 01/01/71 04/01/71 07/01/71 10/01/71 01/01/72 04/01/72 07/01/72 10/01/72
#> [113] 01/01/73 04/01/73 07/01/73 10/01/73 01/01/74 04/01/74 07/01/74 10/01/74
as.chron(time(presidents))
#>   [1] 01/01/45 04/01/45 07/01/45 10/01/45 01/01/46 04/01/46 07/01/46 10/01/46
#>   [9] 01/01/47 04/01/47 07/01/47 10/01/47 01/01/48 04/01/48 07/01/48 10/01/48
#>  [17] 01/01/49 04/01/49 07/01/49 10/01/49 01/01/50 04/01/50 07/01/50 10/01/50
#>  [25] 01/01/51 04/01/51 07/01/51 10/01/51 01/01/52 04/01/52 07/01/52 10/01/52
#>  [33] 01/01/53 04/01/53 07/01/53 10/01/53 01/01/54 04/01/54 07/01/54 10/01/54
#>  [41] 01/01/55 04/01/55 07/01/55 10/01/55 01/01/56 04/01/56 07/01/56 10/01/56
#>  [49] 01/01/57 04/01/57 07/01/57 10/01/57 01/01/58 04/01/58 07/01/58 10/01/58
#>  [57] 01/01/59 04/01/59 07/01/59 10/01/59 01/01/60 04/01/60 07/01/60 10/01/60
#>  [65] 01/01/61 04/01/61 07/01/61 10/01/61 01/01/62 04/01/62 07/01/62 10/01/62
#>  [73] 01/01/63 04/01/63 07/01/63 10/01/63 01/01/64 04/01/64 07/01/64 10/01/64
#>  [81] 01/01/65 04/01/65 07/01/65 10/01/65 01/01/66 04/01/66 07/01/66 10/01/66
#>  [89] 01/01/67 04/01/67 07/01/67 10/01/67 01/01/68 04/01/68 07/01/68 10/01/68
#>  [97] 01/01/69 04/01/69 07/01/69 10/01/69 01/01/70 04/01/70 07/01/70 10/01/70
#> [105] 01/01/71 04/01/71 07/01/71 10/01/71 01/01/72 04/01/72 07/01/72 10/01/72
#> [113] 01/01/73 04/01/73 07/01/73 10/01/73 01/01/74 04/01/74 07/01/74 10/01/74