based off the very generous comments here is a simple solution
rownames(data) <- as.Date(data[,1])
dataxts <- xts(data[,-1], order.by=data[,1])
Question
I'm using R 3.0.2
and I loaded a csv into a dataframe that I want to convert to xts
format.
my data looks something like this
head(data)
V1 V2 V3 V4 V5 V6 V7 V8 V9
1 1999-01-04 1.1812 1.18120 1.18120 1.18120 1.18120 1.18120 1.18120 1.18120
2 1999-01-05 1.1760 1.17860 1.17860 1.17860 1.17860 1.17860 1.17860 1.17860
3 1999-01-06 1.1636 1.17360 1.17360 1.17360 1.17360 1.17360 1.17360 1.17360
4 1999-01-07 1.1672 1.17200 1.17200 1.17200 1.17200 1.17200 1.17200 1.17200
5 1999-01-08 1.1554 1.16868 1.16868 1.16868 1.16868 1.16868 1.16868 1.16555
6 1999-01-11 1.1534 1.16613 1.16613 1.16613 1.16613 1.16613 1.16312 1.15990
following advice from this post I tried to convert the row name as follows
rownames(data) = data[1]
however I get the following error which I can't find my way around
Error in `row.names<-.data.frame`(`*tmp*`, value = value) :
invalid 'row.names' length
Solution
based off the very generous comments here is a simple solution
rownames(data) <- as.Date(data[,1])
dataxts <- xts(data[,-1], order.by=data[,1])