I have an aggregated hierarchical dataset (aggregated per hour) as below
TIME level1 level2 n
<dttm> <fct> <fct> <int>
1 2019-11-29 00:00:00 A a 1
2 2019-11-29 00:00:00 B a 1
3 2019-11-29 00:00:00 B b 2
4 2019-11-29 00:00:00 B c 1
5 2019-11-29 01:00:00 A a 2
6 2019-11-29 02:00:00 A a 1
7 2019-11-29 02:00:00 B a 1
8 2019-11-29 02:00:00 B b 2
9 2019-11-29 02:00:00 B c 1
I want to convert it to hts object and am following the instructions in hts manual and this post on cross validated: https://stats.stackexchange.com/questions/133894/get-groups-in-time-series-with-categorical-data-in-r-for-use-in-gts
I have convert the data into time series (mts) object as
df_mat <- ts(data.matrix(df_agg), frequency = 525960)
Frequency set to hour inline with the aggregation unit in the data frame.
As the number of distinct level1 and level2 can vary, i did not set nrow and ncol object.
After this, i am not very sure how to convert this object to hts. How to generate the arguments nodes, colnames and characters to be passed to the hts method ?
hts(y, nodes, bnames = colnames(y), characters)
Any suggestions ?
Thanks