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_patie...@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@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@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.

Reply via email to