OK. What if I have a time series which is collected every Monday, please? What is the proper way to use the start option within the ts command in order to indicate that this is Monday data, please? Thanks again! Sincerely, Erin
Erin Hodgess wrote:> What if I have a time series which is collected every Monday, please? > > What is the proper way to use the start option within the ts command > in order to indicate that this is Monday data, please? >ts objects don't directly support dates. There is some provision for monthly data, but this isn't the same as uniform, across-the-board date support. What they do have is a start time, a deltat, and frequency (observations per period). The main reason to use ts objects *isn't* the date/time handling, but for the nice functions (acf, spectrum, etc) you can use for regularly spaces time samples. For weekly data, I'd use one of the following approaches (assuming the series starts in the first Monday of 2003): 1) # dates in a year,week format > foo <- ts(1:100,start=c(2003,1),frequency=52) or 2) # dates as numeric representation of POSIXct objects foo <- ts(1:100,start=as.numeric(as.POSIXct("2003-1-6")),deltat=60*60*24*7) > start(foo) [1] 1041764400 > end(foo) [1] 1101639600 > last <- end(foo) > class(last) <- "POSIXct" > last [1] "2004-11-29 New Zealand Daylight Time" (2) depends on as.numeric(POSIXct.object) giving a sensible, single-digit answer. This is not guaranteed. It works today, but nobody promised this approach would work tomorrow. Hope that helps. Cheers Jason -- Indigo Industrial Controls Ltd. http://www.indigoindustrial.co.nz 64-21-343-545 jasont at indigoindustrial.co.nz
On Wednesday 29 October 2003 00:28, Erin Hodgess wrote:> OK. > > What if I have a time series which is collected every Monday, > please? > > What is the proper way to use the start option within the ts command > in order to indicate that this is Monday data, please?In ts you can just generate regularly spaced time series. As the help page states "start" is either a single number or a vector of two integers (tyipically years and months or something similar). So to indiciate that you have monday data you have to store this meta-information in the name of the ts object or the man page, for example. An alternative is to use irregularly spaced time series as provided by irts() in package tseries or its() in package its. Then you always store a full vector of POSIXct times at which the observations were made. Both approaches have certain advantages and disadvantages...depends on what you want to do with the data. hth, Z> Thanks again! > > Sincerely, > Erin > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Well, I'm not sure I understand the question exactly, but you might want to have a look at the package 'its', as Achim said. A practical example might look like: You have a .csv file as follows (I have chosen the date format at random). ,x,y Monday 08-Sep-2003,1,11 Monday 15-Sep-2003,2,22 Monday 22-Sep-2003,3,33 Monday 29-Sep-2003,4,44 Then the following reads the data into an 'its' object require(its) its.format("%A %d-%b-%Y") xy <- its(readcsvIts("c:/temp/weekly.csv"))>From there on it depends what you want to do - 'its'class inherits from matrix, which may be a useful property. - Giles> -----Original Message----- > From: Jason Turner [mailto:jasont at indigoindustrial.co.nz] > Sent: 28 October 2003 23:55 > To: Erin Hodgess > Cc: r-help at stat.math.ethz.ch > Subject: Re: [R] ts vs. POSIX > > > Erin Hodgess wrote: > > What if I have a time series which is collected every > Monday, please? > > > > What is the proper way to use the start option within the ts command > > in order to indicate that this is Monday data, please? > > > > ts objects don't directly support dates. There is some provision for > monthly data, but this isn't the same as uniform, > across-the-board date > support. What they do have is a start time, a deltat, and frequency > (observations per period). The main reason to use ts objects *isn't* > the date/time handling, but for the nice functions (acf, > spectrum, etc) > you can use for regularly spaces time samples. > > For weekly data, I'd use one of the following approaches > (assuming the > series starts in the first Monday of 2003): > > 1) > # dates in a year,week format > > foo <- ts(1:100,start=c(2003,1),frequency=52) > > or > > 2) > # dates as numeric representation of POSIXct objects > foo <- > ts(1:100,start=as.numeric(as.POSIXct("2003-1-6")),deltat=60*60*24*7) > > start(foo) > [1] 1041764400 > > end(foo) > [1] 1101639600 > > last <- end(foo) > > class(last) <- "POSIXct" > > last > [1] "2004-11-29 New Zealand Daylight Time" > > (2) depends on as.numeric(POSIXct.object) giving a sensible, > single-digit answer. This is not guaranteed. It works today, but > nobody promised this approach would work tomorrow. > > Hope that helps. > > Cheers > > Jason > -- > Indigo Industrial Controls Ltd. > http://www.indigoindustrial.co.nz > 64-21-343-545 > jasont at indigoindustrial.co.nz > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >********************************************************************** This is a commercial communication from Commerzbank AG.\ \ T...{{dropped}}