[R] Time Series information in formulae
Claus Dethlefsen
aas.claus.dethlefsen at nja.dk
Tue Apr 11 09:25:59 CEST 2006
Dear List
The UKgas data is stored as an object of class 'ts'. I am trying to use "UKgas"
in a formula as argument to a function. However, I do not know how to access
the 'time series' information in the response (such as start() end() etc.).
Here is a boiled down example.
ssm <- function(formula, data = list(),subset=NULL) {
cl <- match.call()
if (missing(data))
data <- environment(formula)
mf <- match.call(expand.dots = FALSE)
mf$drop.unused.levels <- TRUE
mf[[1]] <- as.name("model.frame")
mf <- eval(mf, .GlobalEnv)
mt <- attr(mf, "terms")
y <- model.response(mf, "numeric")
print(class(y))
}
R> class(UKgas)
[1] "ts"
R> ssm(UKgas~1)
[1] "numeric"
R> ssm(log10(UKgas)~1)
[1] "numeric"
I want the latter two to be "ts". I have tried putting "any" in place
of "numeric" in the call to model.response, but it does not change anything for
me.
How do I retrieve the response from a formula without loosing its "ts" status?
Best,
Claus
----------------------------------------------------
Claus Dethlefsen, MSc, PhD
Biostatistician at Center for Cardiovascular Research
Aalborg Hospital, Aarhus University Hospital, Denmark
More information about the R-help
mailing list