[R] bi-monthly time series
Duncan Mackay
dulcalma at bigpond.com
Thu Feb 20 23:27:21 CET 2014
Hi Michael
What about using zoo you can convert to ts if required
library(zoo)
tv <- seq(as.Date('2005/01/01'),as.Date('2013/01/01'),by=14)
zt <- zoo(vec,tv)
head(zt)
2005-01-01 2005-01-15 2005-01-29 2005-02-12 2005-02-26 2005-03-12
1 0 0 0 1 1
Regards
Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Michael Friendly
Sent: Friday, 21 February 2014 06:04
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