I have xts
time-series object for 10 days of data. The data is sampled at minutes frequency. Therefore, for each day, I have 1440 observations. I need to coerce xts
to ts
object so that I can use stl
function as used in the example. But, On coercion, R generates error as
ts(min_data,start=start(min_data),end = end(min_data),frequency=10)
Error in ts(min_data, start = start(min_data), end = end(min_data), frequency = 10) :
invalid time series parameters specified
I set frequency to 10, since I am using data of 10 days. I am not sure whether it should be 10 or 1440. Can anyone help me to fix this error.
MWE is as
library(xts)
timevalues="20150101 0000/20150110 2359"
timesequence<- timeBasedSeq(timevalues)
min_data<-xts(rnorm(14400),timesequence)
ts_data<- ts(min_data,start=start(min_data), end = end(min_data),frequency=10)
UPDATE
Although I am able to plot the graph using stl
function as suggested by @Pascal, but still I am missing the time component in the x-axis of the graph. Any help will be greatly appreciated.
ts
object, but you should keep yourxts
to manage your 10-minute data. Or if you really need ats
object, I guess the closest you will get is withas.ts(min_data)
.stl()
function of the basic stats package. I triedas.ts()
as wellts_data <- ts(as.numeric(min_data), frequency = 1440); plot(stl(ts_data, s.window = "per"))
.stl
nor you want to work on timestamp in your OP. However, your time stamp aretimesequence
, asNROW(stl(ts_data, s.window = "per")$time.series)
is14400
.