# Date conversion in R, to convert dataset for time series analysis using xts

Hi guys, I need some help,
I am a complete Newbie to R, actually learning it to run my research project

I downloaded MOEX.csv dataset from Investing SA, and R translated it into a Tibble, which i converted to a data.frame,
here is a summary code
moex.data <- as.data.frame(moex.data)

now to convert the date variable which is in the format "Dec 30, 2016" has been a challenge as i have tried all conversion methods I know to no avail.

When I try to run the code
ts.moex.data <- xts(moex.data[,2:5], order.by = moex.data[,1])

I get the following error message
Error in xts(alt.moex.data[, 2:5], order.by = alt.moex.data[, 1]) :
order.by requires an appropriate time-based object

1 Like

Can you provide a reproducible example?

This is so interesting because between the time of posting my topic and getting back to this page,..i found the solution,...it was so simple,..i think i need much reading in R.

Thanks for the instant response,

I will take note of providing a reproducible example, whenever i make a post in the future

Much appreciated.

What was the solution?

For a univariate time series, the first recourse should be to take a vector, which I'll call `V` as an argument to `ts` with an argument for starting date and an argument for frequency. Passing a vector of dates is not needed.

``````V <- as.vector(nhtemp)
my_ts <- ts(V, start = 1912, frequency = 1)
my_ts
#> Time Series:
#> Start = 1912
#> End = 1971
#> Frequency = 1
#>  [1] 49.9 52.3 49.4 51.1 49.4 47.9 49.8 50.9 49.3 51.9 50.8 49.6 49.3 50.6 48.4
#> [16] 50.7 50.9 50.6 51.5 52.8 51.8 51.1 49.8 50.2 50.4 51.6 51.8 50.9 48.8 51.7
#> [31] 51.0 50.6 51.7 51.5 52.1 51.3 51.0 54.0 51.4 52.7 53.1 54.6 52.0 52.0 50.9
#> [46] 52.6 50.2 52.6 51.6 51.9 50.5 50.9 51.7 51.4 51.7 50.8 51.9 51.8 51.9 53.0
``````

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.