seq.yearqtr: zoo seq.yearqtr

Description Usage Arguments Value References Examples

View source: R/toPeriod.R

Description

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
Originally meant to be a zoo S3 object.
Based on the code of seq.Date.

The situation of "no existing seq.yearqtr" drove me nuts!
Therefore I programmed one.
Currently, unlike seq.Date, this function
does not have a difftime implementation.

Currently, unlike seq.Date, this function
does not try to convert to POSIX__.

NOTE: this implementations compliments the gist by adding "by methods"
See. the examples.

Usage

1
2
## S3 method for class 'yearqtr'
seq(from, to, by, length.out = NULL, along.with = NULL, ...)

Arguments

from

See ? seq.Date

to

See ? seq.Date

by

See ? seq.Date. See examples (below).

length.out

See ? seq.Date

along.with

See ? seq.Date

...

See ? seq.Date

Value

zoo as.yearqtr class

References

R zoo S3 object seq.yearqtr seq.yearmon https://gist.github.com/AndreMikulec/aceb20a0b6c170027b035519ca7a3adb

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
## Not run: 
seq.yearqtr(as.yearqtr("2000 Q1"), to = as.yearqtr("2002 Q1"))
# Error in seq.yearqtr(as.yearqtr("2000 Q1"), to = as.yearqtr("2002 Q1")) :
#  exactly two of 'to', 'by' and 'length.out' / 'along.with' must be specified
# That was the expected output!

seq.yearqtr(as.yearqtr("2000 Q1"), to = as.yearqtr("2002 Q1"), length.out = 2)
# [1] "2000 Q1" "2002 Q1"

seq.yearqtr(as.yearqtr("2000 Q1"), to = as.yearqtr("2002 Q1"), length.out = 3)
# [1] "2000 Q1" "2001 Q1" "2002 Q1"

seq.yearqtr(as.yearqtr("2000 Q1"), to = as.yearqtr("2002 Q1"), length.out = 4)
# [1] "2000 Q1" "2000 Q4" "2001 Q2" "2002 Q1"

seq.yearqtr(as.yearqtr("2000 Q1"), to = as.yearqtr("2002 Q1"), by = 1/4)
# [1] "2000 Q1" "2000 Q2" "2000 Q3" "2000 Q4" "2001 Q1" "2001 Q2" "2001 Q3"
# [8] "2001 Q4" "2002 Q1"

seq.yearqtr(as.yearqtr("2000 Q1"), to = as.yearqtr("2002 Q1"), by = 2/4)
# [1] "2000 Q1" "2000 Q3" "2001 Q1" "2001 Q3" "2002 Q1"

seq.yearqtr(as.yearqtr("2000 Q1"), to = as.yearqtr("2002 Q1"), by = "2 yearqtrs")
# [1] "2000 Q1" "2000 Q3" "2001 Q1" "2001 Q3" "2002 Q1"

seq.yearqtr(as.yearqtr("2000 Q1"), to = as.yearqtr("2002 Q1"), by = "2 quarters")
# [1] "2000 Q1" "2000 Q3" "2001 Q1" "2001 Q3" "2002 Q1"

seq.yearqtr(as.yearqtr("2002 Q1"), to = as.yearqtr("2000 Q1"), by = -1/4)
# [1] "2002 Q1" "2001 Q4" "2001 Q3" "2001 Q2" "2001 Q1" "2000 Q4" "2000 Q3"
# [8] "2000 Q2" "2000 Q1"

seq.yearqtr(as.yearqtr("2002 Q1"), to = as.yearqtr("2000 Q1"), by = "-1 yearqtrs")
# [1] "2002 Q1" "2001 Q4" "2001 Q3" "2001 Q2" "2001 Q1" "2000 Q4" "2000 Q3"
# [8] "2000 Q2" "2000 Q1"


## End(Not run)

AndreMikulec/econModel documentation built on June 30, 2021, 9:48 a.m.