Re: [R] Adding dates to time series

From: Dennis Murphy <djmuser_at_gmail.com>
Date: Sun, 15 May 2011 14:18:19 -0700

Hi:

I'd suggest using the zoo package; it allows you to use an index vector such as dates to map to the series. It is well documented and well maintained, with vignettes and an FAQ that can be found on its package help page (among other places). Here is a small example:

dd <- data.frame(time = seq(as.Date('1993-01-01'), by = 'months', length = 200),

                     s = rnorm(200))
head(dd, 3)
        time          s
1 2003-01-01  1.4292491

2 2003-02-01 -1.0713998
3 2003-03-01 -0.4738791

library(zoo)
ser <- with(dd, zoo(s, time)) # s is the series, time is the index vector str(ser) # ser is of class zoo
plot(ser) # apply the plot method

For finance applications, other possibilities include the xts and quantmod packages, both of which are built on zoo.

HTH,
Dennis

On Sun, May 15, 2011 at 11:42 AM, Bazman76 <h_a_patience_at_hotmail.com> wrote:
> Hi there,
>
> I have a spreadsheet in excel which consists of first column  of dates and
> then subsequent columns that refer to prices of different securities on
> those dates. (the first row contains each series name)
>
> I saved the excel file as type csv and then imported to excel using
>
> prices=read.csv(file="C:/Documents and Settings/Hugh/My Documents/PhD/Option
> prices.csv",header = TRUE, sep = ",")
>
> This creates the correct time series data
>
> x<-ts(prices[,2])
>
> but does not have the dates attached.
>
> However the dates refer to working days. So although in general they
> represent Monday-Friday this is not always the case because of holidays etc.
>
> How then can I create a time series where the dates are read in from the
> first column of the csv file? I can not find an example in R documentation
> where this is done?
>
> Thanks
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Adding-dates-to-time-series-tp3524679p3524679.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 15 May 2011 - 21:21:04 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 15 May 2011 - 23:40:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive