[R] Reading in irregular, daily time series data

veol jonnybaik at gmail.com
Thu Nov 4 09:57:20 CET 2010


I am trying to read in some time series data and am having trouble. Forgive
me, I am quite new to R. The data is in the form of:

"2000-07-28" 1419.89
"2000-07-31" 1430.83
"2000-08-01" 1438.1
"2000-08-02" 1438.7
"2000-08-03" 1452.56
"2000-08-04" 1462.93
"2000-08-07" 1479.32
"2000-08-08" 1482.8
"2000-08-09" 1472.87
"2000-08-10" 1460.25
"2000-08-11" 1471.84
"2000-08-14" 1491.56
"2000-08-15" 1484.43

The data is daily data, but it is irregular (i.e. there are some missing
data points). 

I have tried reading in the data like so, but when I plot, the time series
does not preserve the dates.

sp500 <- ts(read.table("SP500.txt",header=TRUE))

I have searched the forums, and have found the current method to work:

sp500 <- read.table("SP500.txt",header=TRUE)
date <- sp500[,1]
data <- sp500[,2]
z <- aggregate(zoo(data), as.Date(date), tail, 1)
merge(z, zoo(, as.Date(unclass(time(as.ts(z))), fill=0)))

However, now I cannot analyze the acf of the time series, as R complains
giving an error:
Error in na.fail.default(as.ts(x)) : missing values in object

Is there any way to fix this?

I would actually prefer not using the zoo class, as it breaks the acf
function in R. Would the new zoo object be compatible with all the ts

Thank you!

View this message in context: http://r.789695.n4.nabble.com/Reading-in-irregular-daily-time-series-data-tp3026688p3026688.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list