[R] Dropping time series observations

William Dunlap wdunlap at tibco.com
Sat Jan 31 23:52:53 CET 2015


For class 'ts' the 'window' function in the base package will do it.

> x <- ts(101:117, start=2001.75, frequency=4)
> x
     Qtr1 Qtr2 Qtr3 Qtr4
2001                 101
2002  102  103  104  105
2003  106  107  108  109
2004  110  111  112  113
2005  114  115  116  117
> window(x, start=2002.5)
     Qtr1 Qtr2 Qtr3 Qtr4
2002            104  105
2003  106  107  108  109
2004  110  111  112  113
2005  114  115  116  117
> window(x, end=2002.5)
     Qtr1 Qtr2 Qtr3 Qtr4
2001                 101
2002  102  103  104



Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sat, Jan 31, 2015 at 11:16 AM, Mikael Olai Milhøj <mikaelmilhoj at gmail.com
> wrote:

> Hi
>
> Is there an easy way to drop, for instance, the first 4 observation of a
> time series object in R? I have tried to google the answer without any
> luck.
>
> To be more clear:
> Let us say that I have a time seres object x which data from 2000Q1 to
> 2014Q4 but I only want the data from 2001Q1 to 2014Q4.How do I remove the
> first four elements?
>
> By using x[5:?] R no longer recognize it as a ts.object.
>
> Thank you
>
> Best regards
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list