I have a large data frame with dates and data. In every odd column I have the dates and every second column the corresponding stock price. I would like to convert every column pair to a separate xts object. The data frame looks like this:
...1 Stock Price
2021-11-09 72.5
2021-11-10 73.4
2021-11-15 72.9
etc etc
when I call the following line it works fine:
xts(df[,2],order.by=df$...1)
However I want to use it in a loop so I rather use
xts(df[,2],order.by=df[,1])
,
but this leads to an error. order.by requires an appropriate time-based object.
When I try this : xts(df[,2],order.by=as.Date(df[,1]))
it pops up do not know how to convert 'x' to class “Date”. I do not understand as originaly the first column is in posixct format.
Could someone suggest me a solution?
Thank you