View source: R/ar_conversion.R
m_to_q | R Documentation |
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
m_to_q(x, type)
type |
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.