jeep740
jeep740

Reputation: 15

ts() function in R with daily observations

I have daily data from 01/01/2019 to 31/05/2019, which I want to transform into a time series. Using the ts() function in R, I have set the start parameter as c(2019,1,1) the end parameter as c(2019,5,31) and the frequency as 7, as seen below.

time_series = ts(x,start=c(2019,1,1), end=c(2019,5,31),frequency=7)

I do not obtain the expected time series plot. I think perhaps the end parameter is incorrect, because if I remove it I obtain a better time series plot2 but time axis is incorrect.

How do I fix the time series so that I obtain a daily time series which runs from 01/01/2019 to 31/05/2019?

x is the number of observations per day.

x=c(102,163,174,176,120,116,195,165,165,176,159,111,97,163,167,175,157,127,82,102,152,165,173,158,118,89,120,167,154,160,168,242,98,123,171,131,166,188,157,86,141,188,161,169,172,183,94,93,174,149,162,149,141,107,116,167,176,167,223,148,110,132,193,181,143,125,167,111,112,181,182,202,176,144,103,117,189,164,172,191,160,113,123,188,173,151,163,163,91,151,170,138,131,188,167,104,115,171,183,185,162,138,112,119,177,111,115,143,86,92,132,182,164,172,174,149,91,137,196,123,143,178,137,115,112,183,200,191,170,145,103,120,187,171,188,184,147,101,138,183,169,86,160,151,118,104,178,202,158,131,129)

Upvotes: 0

Views: 619

Answers (1)

Waldi
Waldi

Reputation: 41210

It will probably be easier with xts, see

library(xts)
dates <- as.Date("2019-01-01")+(0:(length(x)-1))
ts <- xts(x,dates)     
plot(ts)

enter image description here

Upvotes: 1

Related Questions