Skip to content
Prev 259930 / 398502 Next

Adding dates to time series

On Sun, May 15, 2011 at 2:42 PM, Bazman76 <h_a_patience at hotmail.com> wrote:
Lines <- "time,s
2003-01-01,1.4292491
2003-02-01,-1.0713998
2003-03-01,-0.4738791"

library(zoo)

# F <- "C:/Documents and Settings/Hugh/My Documents/PhD/Option prices.csv"
# z <- read.zoo(F, header = TRUE, sep = ",")

# in reality we would read from the file as shown in the comments above
# but here we do it this way so we can just copy it and paste it
# verbatim into the R session

z <- read.zoo(textConnection(Lines), header = TRUE, sep = ",")

If you want xts then:

library(xts)
x <- as.xts(z)

Note that ts is not good for dates so use zoo or xts.

See ?read.zoo in the zoo package.