I get always a data table of this format:
set.seed(123)
dt <- data.table(date = seq(as.Date('2020-01-01'), by = '1 day', length.out = 365),
Germany = rnorm(365, 2, 1), check.names = FALSE)
The data table dt
is only a counterexample. Every day of a month has a value (price), but it is also possible that a day has an NA-value.
... can be understood as any value.
What I want to do is, to change the format of this data table into the following form (colors can be ignored):
The first column defines the months of the year and all other columns are declaring the dates, e.g. price on the 2nd Jan is 2.11 or on the 31th Sept is 1.78. How can I do this?