[R] Import time series data with uneven dates
Heywood, Giles
Giles.Heywood at CommerzbankIB.com
Thu Jun 19 09:03:42 CEST 2003
A solution is at hand using the 'irts' (irreglar time-series)
class from package tseries.
If your raw data is in a csv file, you could proceed as follows:
mydata <- read.csv(filename,header=TRUE)
basedate <- as.POSIXct(strptime("2003-01-01 00:00:00",format="%Y-%m-%d %X"))
rawdates <- basedate+(mydata[,1]-floor(mydata[,1]))*24*60*60*365 -60*60
truncdates <-
as.POSIXct(strptime(format.POSIXct(rawdates,format="%Y-%m-%d"),,format="%Y-%
m-%d"))
require(tseries)
x <- irts(time=truncdates,mydata[,2])
The result is an object of class 'irts'.
The format of the dates in your file is particularly unhelpful! If
they are available in a format recognisable by strptime, the above
could be simplified and made more robust.
Incidentally, I plan to post a slightly different 'its' (irregular
time-series) package sometime soon.
Giles
> -----Original Message-----
> From: Ariel Andres [mailto:aandres1 at cogeco.ca]
> Sent: 19 June 2003 03:51
> To: r-help at stat.math.ethz.ch
> Subject: [R] Import time series data with uneven dates
>
>
> I am trying to import a file of daily index closing prices in
> business time
> which excludes weekends and holidays so deltat is not
> constant. My file
> looks like the following:
> date close
> 2003.0055 47.05
> 2003.0082 45.71
> 2003.0164 43.45
> 2003.0192 42.96
> 2003.0219 44.56
> 2003.0247 42.99
> 2003.0274 42.28
> 2003.0356 41.74
> etc.
>
> >From what I saw in the EuStockMarkets file, it appears that
> they are also
> using years and fractions of years as the measure of time.
> How do I read my
> file and still keep 'date' as the date?
>
> Thanks!
>
> A. Andres
> 95 Wellington St W
> Toronto, Ontario
> M5J 2N7
>
> ______________________________________________
> 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.\ \ This ... {{dropped}}
More information about the R-help
mailing list