Daily time series with ts .. how to indicate start and end

I have a daily time series that starts on Saturday and ends on Wednesday. For him, there is a clear weekly period. It is stored in vector a in R. So, I'm trying to convert it to an object in a time series -

ts(a,frequency=7)

It gives me -

Time Series:
Start = c(1, 1) 
End = c(13, 5) 

What do (1,1) and (13.5) mean? And what is the best way to indicate the beginning and end in this scenario. All examples on the Internet are related to annual data, not daily.

+4
source share
1 answer

Let's look at how it tsworks with different frequencies using documentation ( ?ts)

Let's say this is your data

dat <- data.frame(myts = sample(10, 24, replace = T),
                  Date = seq(as.Date("2008-10-11"), as.Date("2008-10-11") + 23, by = 1))

# myts       Date
# 1     6 2008-10-11
# 2     9 2008-10-12
# 3     6 2008-10-13
# 4     9 2008-10-14
# 5     8 2008-10-15
# 6     6 2008-10-16
# 7     1 2008-10-17
# 8     9 2008-10-18
# 9     3 2008-10-19
# 10    5 2008-10-20
# 11    7 2008-10-21
# 12    4 2008-10-22
# 13    2 2008-10-23
# 14    9 2008-10-24
# 15    5 2008-10-25
# 16    9 2008-10-26
# 17    7 2008-10-27
# 18    8 2008-10-28
# 19    7 2008-10-29
# 20    2 2008-10-30
# 21    6 2008-10-31
# 22    6 2008-11-01
# 23    8 2008-11-02
# 24    1 2008-11-03

print(ts(dat$myts, frequency = 7, start = c(1950, 3)), calendar = T)
#      p1 p2 p3 p4 p5 p6 p7
# 1950        6  9  6  9  8
# 1951  6  1  9  3  5  7  4
# 1952  2  9  5  9  7  8  7
# 1953  2  6  6  8  1      
print(ts(dat$myts, frequency = 12, start = c(1950, 3)), calendar = T)
#      Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
# 1950           6   9   6   9   8   6   1   9   3   5
# 1951   7   4   2   9   5   9   7   8   7   2   6   6
# 1952   8   1                                        
print(ts(dat$myts, frequency = 4, start = c(1950, 3)), calendar = T)
#      Qtr1 Qtr2 Qtr3 Qtr4
# 1950              6    9
# 1951    6    9    8    6
# 1952    1    9    3    5
# 1953    7    4    2    9
# 1954    5    9    7    8
# 1955    7    2    6    6
# 1956    8    1          
print(ts(dat$myts, frequency = 7), calendar = T)
#   p1 p2 p3 p4 p5 p6 p7
# 1  6  9  6  9  8  6  1
# 2  9  3  5  7  4  2  9
# 3  5  9  7  8  7  2  6
# 4  6  8  1    

3

1- ts 12 4 , 7 .

2- start - , , ( ).

3- , ts , ( , (1,1) )

, , ( , 52 ) (: 1 = , 2 = ..) start (. ?strftime)

startW <- as.numeric(strftime(head(dat$Date, 1), format = "%W"))
startD <- as.numeric(strftime(head(dat$Date, 1) + 1, format =" %w")) 
print(ts(dat$myts, frequency = 7, start = c(startW, startD)), calendar = T)
#   p1 p2 p3 p4 p5 p6 p7
#39                    6
#40  9  6  9  8  6  1  9
#41  3  5  7  4  2  9  5
#42  9  7  8  7  2  6  6
#43  8  1   

, ( 2008-10-11) 39- 2008 .

+12

Source: https://habr.com/ru/post/1540196/


All Articles