Coerce the data.frame into a ts object

Viewed 21

I have data that is recorded hourly from 09:00 on Wednesday 01 September 2021 to 00:00 on Thursday 16 September 2021. I'm struggling to convert this into a ts object. I'm fairly new to R studio and mostly worked with quarterly and yearly data sets. Snippet of the data

EDIT

For example, this is how I usually approach ts problems.

This is my code:

data <- read.csv("quarterly_data.csv")
data <- ts(value, start = c(1972, 3), frequency = 4)
str(data)

Expected output:

         Qtr1     Qtr2     Qtr3     Qtr4
1972                   331.0423 330.6809
1973 332.8908 339.0712 330.8882 317.4027
1974 323.7338 330.3634 315.0752 302.3647
1975 311.7815 303.1836 315.6477 303.1407
1976 311.9433 304.2641 307.2372 315.9292
1977 294.7084 288.5990 290.1560 293.3352
1978 295.2539 296.5926 289.4252 280.3545
1979 284.2890 283.9004 268.5119 282.4164
1980 263.6612 275.2818 269.1706 270.2707
1981 266.4499 263.5661 262.0435 256.6394

Example of quarterly_data.csv data:

index,value
1972 Q3,331.04231737120716
1972 Q4,330.6809436377971
1973 Q1,332.89077655317857
1973 Q2,339.0712129732076
1973 Q3,330.88815547584187
1973 Q4,317.40273502302176
1974 Q1,323.73378912972066

But for my problem

This is my code:

channels <- read.csv("twitch_channels.csv")
channels_ts <- ts(data = channels$Channels, start = c(01, 09)), frequency = 24)
str(channels_ts)
channels_ts

Output:

[1]  2687  2865  3764  4305  4042  5198  4876  4552  7062  4716  3816  4857  6884  6655  4830  6782  7471  6598
 [19]  7019  8220  7649  6574  7482  5227  6056  7597  7609  6789  8048  8760  9777  7909  8593 10425  9508 10525
 [37]  9582  7919  9351  8254  9323 10366  9226  9878  9093  6006  7551  8753  7486  7862  7705  9039  9072  8793
 [55]  8505  9489  8378  7325  5461  5923  8505  5791  5827  7283  7734  7459  6552  6740  5784  6174  6089  4686
 [73]  4849  2912  2786  6186  3404  5138  5093  4894  5120  5726  6257  6070  6027  3371  3312  4682  5168  4167
 [91]  5576  4088  5982  4509  3843  3464  3773  3170  4653  4821  4318  3689  5158  4558  5133  6428  5963  4209
[109]  6990  2232  2135  3507  6753  4203  6258  4047  4532  3375  3283  2328  3823  2743  4898  4962  1949  3635
[127]  6449  4343  4830  4182  6125  4839  3737  3564  3100  3335  4836  3538  3163  5267  5822  2945  3630  2108
[145]  1809  2227  1932  3807  1675  2433  4797  5002  4161  4910  4171  3987  3332  2655  2142  2822  3873  4172
[163]  4417  3070  3791  4257  2432  4106  1895  2378  2288  1656  2670  4081  2159  3579  3822  4345  3364  4488

Example of twitch_channels.csv data:

Date,Channels
2021-09-01T09:00:00Z,2687
2021-09-01T10:00:00Z,2865
2021-09-01T11:00:00Z,3764
2021-09-01T12:00:00Z,4305
2021-09-01T13:00:00Z,4042
2021-09-01T14:00:00Z,5198
2021-09-01T15:00:00Z,4876
2021-09-01T16:00:00Z,4552
2021-09-01T17:00:00Z,7062
2021-09-01T18:00:00Z,4716
2021-09-01T19:00:00Z,3816

The output doesn't make sense to me, how do I convert my data.frame into a ts object that is easier to read like the output for quarterly data?

0 Answers
Related