I have a spreadsheet in excel which consists of first row of dates and then subsequent columns that refer to prices of different securities on those dates.
I saved the excel file as a 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 where this is done
As you didn't give any data, here is a made-up data.frame:
I used
within()
, you can use other means to in order to assign new columns. The key is thatpaste()
allows you to combine columns, and you could use other R functions to modify the data as needed.The key advantage of having dates and times parsed in a suitable type (like
POSIXct
) is that other functions can then use it. Here is zoo: