[R] bi-monthly time series

David Carlson dcarlson at tamu.edu
Thu Feb 20 22:19:40 CET 2014


If the data are two week intervals, the frequency is 52/2 = 26
and that matches the amount of data 8*26=208:

> vec.ts <- ts(vec, start=c(2005, 1), frequency=26)
> str(vec.ts)
 Time-Series [1:208] from 2005 to 2013: 1 0 0 0 1 1 1 0 2 0 ...
> print(vec.ts, calendar=TRUE)
     p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16
2005  1  0  0  0  1  1  1  0  2   0   1   0   3   1   1   2
2006  1  0  1  0  0  1  1  0  1   0   1   1   0   0   3   0
2007  1  0  0  0  3  0  1  1  1   0   0   0   1   0   0   0
2008  0  1  0  1  0  1  0  1  1   0   0   0   1   0   0   1
2009  0  1  1  0  0  0  0  2  0   1   1   0   0   2   0   0
2010  1  0  1  1  0  2  0  1  1   0   1   0   0   0   1   1
2011  1  0  1  0  0  1  1  1  2   0   1   1   1   0   0   2
2012  1  0  0  0  0  1  2  0  0   1   0   0   0   2   1   1
     p17 p18 p19 p20 p21 p22 p23 p24 p25 p26
2005   0   0   1   0   0   0   3   0   2   0
2006   0   3   1   1   1   0   1   1   0   1
2007   0   2   0   0   1   0   0   0   2   1
2008   0   0   1   1   0   1   0   2   0   2
2009   0   0   1   0   0   1   1   0   1   0
2010   0   0   0   0   0   0   0   0   0   0
2011   0   0   0   0   1   1   1   0   1   0
2012   0   0   0   0   0   1   1   1   1   0

But str() seems to round up on the year for some reason.

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of Michael
Friendly
Sent: Thursday, February 20, 2014 2:04 PM
To: R-help
Subject: [R] bi-monthly time series


The vector, vec, below represents a time series of the number of
some 
events recorded
for 208 two-week intervals from 2005/01/01 up to the end of
2012.  I 
want to
represent this together with the date information.  I tried
ts(), but 
don't quite understand
how to use the start=, end= and frequency= arguments in this
case.

vec <- c(
1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 2L, 0L, 1L, 0L, 3L, 1L, 1L,
2L, 0L, 0L, 1L, 0L, 0L, 0L, 3L, 0L, 2L, 0L, 1L, 0L, 1L, 0L, 0L,
1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 3L, 0L, 0L, 3L, 1L, 1L, 1L,
0L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 3L, 0L, 1L, 1L, 1L, 0L, 0L,
0L, 1L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 1L, 0L, 0L, 0L, 2L, 1L, 0L,
1L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L,
0L, 1L, 1L, 0L, 1L, 0L, 2L, 0L, 2L, 0L, 1L, 1L, 0L, 0L, 0L, 0L,
2L, 0L, 1L, 1L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L,
0L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 2L, 0L, 1L, 1L, 0L, 1L, 0L, 0L,
0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L,
0L, 0L, 1L, 1L, 1L, 2L, 0L, 1L, 1L, 1L, 0L, 0L, 2L, 0L, 0L, 0L,
0L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 2L, 0L, 0L,
1L, 0L, 0L, 0L, 2L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L,
0L)

This is what I tried, but it doesn't seem right because str()
reports 
... to 2014.

 > vec.ts <- ts(vec,
+ start=c(2005,1),
+ frequency=24
+ )
 >
 > str(vec.ts)
  Time-Series [1:208] from 2005 to 2014: 1 0 0 0 1 1 1 0 2 0 ...
 >

If instead of a time series, I attached date names to the
observations, 
they would be something
like

names(vect) <-
seq(as.Date('2005/01/01'),as.Date('2013/01/01'),by=14)

but that's awkward to work with.

-- 
Michael Friendly     Email: friendly AT yorku DOT ca
Professor, Psychology Dept. & Chair, Quantitative Methods
York University      Voice: 416 736-2100 x66249 Fax: 416
736-5814
4700 Keele Street    Web:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

______________________________________________
R-help at r-project.org mailing list
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.




More information about the R-help mailing list