[R-SIG-Finance] Creating an index based on a time variable

Am Gut agquantr at gmail.com
Wed Oct 21 21:05:50 CEST 2015


Everyone,

I would appreciate some help on a very basic topic that I have been
struggling with for quite a while. I am using the xts packages and have
gone through quite a bit of documentation in search of how to create a time
index based on a time column in my dataset.

I am following the code used directly in the xts package documentation and
would greatly appreciate it if someone would help. The beginning of my
imported dataset looks like:

row.names Consumer Discretionary Consumer Staples 1/31/1995 0.6468773
2.047813 2/28/1995 3.39433 2.866054 3/31/1995 3.0161 2.887118 4/28/1995
-1.341188 2.826405 5/31/1995 4.459739 4.309547 6/30/1995 2.636647 1.610363
7/31/1995 3.298938 -0.002974272

I am using the following code:

require(xts)
sector_returns = read.csv("Sector.csv", head=TRUE)
class(sector_returns)

sector_returns = as.matrix(sector_returns)
sector_xts = as.xts(sector_returns,dateFormat='Date')

the last line gives me the following error:

Error in as.xts.matrix(sector_returns, dateFormat = "Date") :
  order.by must be either 'rownames()' or otherwise specified

I have tried a few different ways of using the rownames function and have
had zero success. I apologize if this question is extremely basic, as I
have made significant effort trying to get this to work. Any help on
assigning the rownames to my date variable (row.names column) would be
extremely helpful.

Thanks in advance,

AG

	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list