Skip to contents

Convert a reporting square matrix to a long data frame

Usage

nowcast_matrix_to_df(matrix, draw = NULL)

Arguments

matrix

Matrix in the form of a reporting triangle/square, where the rows indicate the reference time and the columns indicate the delay.

draw

integer tracking the draw that the reporting matrix corresponds to. Default is NULL which will not return a draw column.

Value

A long dataframe of the length of the product of the number of columns and the number of rows, with information on what time and delay the observation corresponds to.

Examples

nowcast_matrix <- matrix(
  c(
    80, 50, 25, 10,
    100, 50, 30, 20,
    90, 45, 25, 18,
    80, 40, 24, 16,
    70, 35, 21, 19,
    67, 34, 15, 9
  ),
  nrow = 6,
  byrow = TRUE
)

long_df <- nowcast_matrix_to_df(nowcast_matrix)
print(long_df)
#>    time delay count
#> 1     1     1    80
#> 2     1     2    50
#> 3     1     3    25
#> 4     1     4    10
#> 5     2     1   100
#> 6     2     2    50
#> 7     2     3    30
#> 8     2     4    20
#> 9     3     1    90
#> 10    3     2    45
#> 11    3     3    25
#> 12    3     4    18
#> 13    4     1    80
#> 14    4     2    40
#> 15    4     3    24
#> 16    4     4    16
#> 17    5     1    70
#> 18    5     2    35
#> 19    5     3    21
#> 20    5     4    19
#> 21    6     1    67
#> 22    6     2    34
#> 23    6     3    15
#> 24    6     4     9