m_to_q: aggregates, or converts, from monthly to quarterly

Description Usage Arguments Examples

View source: R/ar_conversion.R

Description

I based this on the as.quarterly function that is in the tframePlus package I set it up so you have to give a type of aggregation it works for type=sum or type=mean The ts line is basically converting a series from xts to ts, because the ts works as an input to as.quarterly One reason that I believe I needed to set this up was that I want to be able to run it accross columns of an xts object, which one can't typically do with apply. also, the aggregate.zoo function will sum up the months to a quarterly value even if the last month is missing, for example: tempc_m <- opcl_m$totusoprms tempc_q <- aggregate(tempc_m, as.yearqtr, sum) tempc_q <- xts(tempc_q) so this is what I came up with

Usage

1

Arguments

type

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# as an example of using this function is the steps I had in
#load_str_openclose, which are as follows
start <- as.yearqtr((start(opcl_m)))
h <- zooreg(vapply(opcl_m, m_to_q, FUN.VALUE =
                    numeric(floor(nrow(opcl_m)/3)),
                  type="sum"), start=start, frequency=4)
opcl_q <- xts(h)
indexClass(opcl_q) <- c("Date")

a couple examples of as.quarterly for reference
z <- ts(1:10, start = c(1999,2), frequency=4)
z
as.annually(z)
as.annually(z, na.rm=TRUE)

z <- ts(1:30, start = c(1999,2), frequency=12)
z
as.annually(z)
as.annually(z, na.rm=TRUE)
as.quarterly(z)
as.quarterly(z, na.rm=TRUE)

aranryan/arlodr documentation built on Oct. 8, 2020, 12:46 p.m.