Hi all,
for reference: I can't really see this as a feature, so I reported the bug
here:
https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=15765
Cheers
Joris
On Sat, Apr 19, 2014 at 11:42 AM, Joris Meys <jorismeys@gmail.com> wrote:
> Dear all,
>
> Before I file this as a bug, I wanted to check if I didn't miss
something.
> The help page of lag() says that the function returns a time series object.
> It actually does return something that looks like a ts object (the
> attribute tsp is set). But when using a vector, the class "ts" is
not added
> to the result:
>
> > avec <- 1:10
> > lag(avec)
> [1] 1 2 3 4 5 6 7 8 9 10
> attr(,"tsp")
> [1] 0 9 1
> > as.ts(lag(avec))
> Time Series:
> Start = 0
> End = 9
> Frequency = 1
> [1] 1 2 3 4 5 6 7 8 9 10
> > class(lag(avec))
> [1] "integer"
> > class(as.ts(lag(avec)))
> [1] "ts"
>
> Am I missing something, or would the lag() function benefit from a small
> adjustment :
>
> function (x, k = 1, ...)
> {
> if (k != round(k)) {
> k <- round(k)
> warning("'k' is not an integer")
> }
> x <- hasTsp(x)
> p <- tsp(x)
> tsp(x) <- p - (k/p[3L]) * c(1, 1, 0)
> as.ts(x) # adjusted, was simply x before
> }
>
> Cheers
> Joris
> --
> Joris Meys
> Statistical consultant
>
> Ghent University
> Faculty of Bioscience Engineering
> Department of Mathematical Modelling, Statistics and Bio-Informatics
>
> tel : +32 9 264 59 87
> Joris.Meys@Ugent.be
> -------------------------------
> Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
>
--
Joris Meys
Statistical consultant
Ghent University
Faculty of Bioscience Engineering
Department of Mathematical Modelling, Statistics and Bio-Informatics
tel : +32 9 264 59 87
Joris.Meys@Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
[[alternative HTML version deleted]]