On Feb 20, 2014, at 12:03 PM, Michael Friendly wrote: > > 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 > + )
The nominal number of weeks in a year is 52 so bi-weekly events would be 26 per year: > 365/7/2 [1] 26.07143 There is als a seq.Date method taht accepts a vy argument so: > wvec <- data.frame(dt = seq(as.Date("2005-01-01"), by="2 week", length=208), > vec) > str(wvec) 'data.frame': 208 obs. of 2 variables: $ dt : Date, format: "2005-01-01" "2005-01-15" ... $ vec: int 1 0 0 0 1 1 1 0 2 0 ... Or as mentioned zoo methods which are generally much easier to work with than ts-objects. David. > > > > 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 > David Winsemius Alameda, CA, USA ______________________________________________ R-help@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.