[R] ts vs. POSIX
Heywood, Giles
Giles.Heywood at CommerzbankIB.com
Wed Oct 29 09:12:05 CET 2003
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}}
More information about the R-help
mailing list