Amitai
Amitai

Reputation: 891

Creating time series in R with given time-stamps and values

I create the following time series

t = seq(as.POSIXct('2014-12-05 10:01:00'), length.out = 4, by = 'mins')
x = c(1,3,4,2)
y = as.ts(x,t)

When I try to view (in a plot) my time series, the time tags are not the values I entered in t.

plot(y)
time(y)
[1] 1 2 3 4

How can I fix it?

Upvotes: 1

Views: 183

Answers (1)

J.R.
J.R.

Reputation: 3888

I would use the xts package, ie. create the Time-Series as an xts object instead and then leverage on plot.xts:

library(xts)
y.xts <- xts(x, t)
plot(y.xts)  

enter image description here

Upvotes: 1

Related Questions