Skip to contents

bind is a wrapper around bind_rows with a dedicated method for harp_list objects. In all other cases bind_rows is called.

Usage

bind(..., .id = NULL)

Arguments

...

A list or a harp_list object

.id

The name of the column to be used to identify each element of the list in the resulting data frame

Value

A data frame with the class of the first data frame in the list

Details

For harp_list objects, the name of each element in the list is added to each data frame as a column, with the heading as given in the .id argument. For forecast data the prefix before "_det" for deteriministic forcasts and the prefix before "_mbr***" for ensemble forecasts are removed from the column headings. For multimodel ensembles, this could lead to problems with columns having the same heading.

It should be noted that no check is made on the classes of the data frames in the harp_list object, and the class of the first is used in the output.

Examples

bind(
  as_harp_list(
    a = as_harp_df(data.frame(
      valid_dttm = as_dttm(seq_dttm(2021010100, 2021010123)),
      a_det = runif(24)
    )),
    b = as_harp_df(data.frame(
      valid_dttm = as_dttm(seq_dttm(2021010100, 2021010123)),
      b_det = runif(24)
    ))
  )
)
#> ::deterministic point forecast:: # A tibble: 48 × 3
#>    fcst_model valid_dttm            fcst
#>    <chr>      <dttm>               <dbl>
#>  1 a          2021-01-01 00:00:00 0.885 
#>  2 a          2021-01-01 01:00:00 0.468 
#>  3 a          2021-01-01 02:00:00 0.377 
#>  4 a          2021-01-01 03:00:00 0.569 
#>  5 a          2021-01-01 04:00:00 0.595 
#>  6 a          2021-01-01 05:00:00 0.238 
#>  7 a          2021-01-01 06:00:00 0.215 
#>  8 a          2021-01-01 07:00:00 0.996 
#>  9 a          2021-01-01 08:00:00 0.0764
#> 10 a          2021-01-01 09:00:00 0.399 
#> # ℹ 38 more rows
bind(
  as_harp_list(
    a = as_harp_df(data.frame(
      valid_dttm = as_dttm(seq_dttm(2021010100, 2021010123)),
      a_mbr000  = runif(24),
      a_mbr001  = runif(24)
    )),
    b = as_harp_df(data.frame(
      valid_dttm = as_dttm(seq_dttm(2021010100, 2021010123)),
      b_mbr000 = runif(24),
      b_mbr001 = runif(24)
    ))
  )
)
#> ::ensemble point forecast [[long]]:: # A tibble: 96 × 5
#>    fcst_model sub_model valid_dttm          member   fcst
#>    <chr>      <chr>     <dttm>              <chr>   <dbl>
#>  1 a          a         2021-01-01 00:00:00 mbr000 0.545 
#>  2 a          a         2021-01-01 00:00:00 mbr001 0.104 
#>  3 a          a         2021-01-01 01:00:00 mbr000 0.0665
#>  4 a          a         2021-01-01 01:00:00 mbr001 0.561 
#>  5 a          a         2021-01-01 02:00:00 mbr000 0.136 
#>  6 a          a         2021-01-01 02:00:00 mbr001 0.977 
#>  7 a          a         2021-01-01 03:00:00 mbr000 0.721 
#>  8 a          a         2021-01-01 03:00:00 mbr001 0.0277
#>  9 a          a         2021-01-01 04:00:00 mbr000 0.627 
#> 10 a          a         2021-01-01 04:00:00 mbr001 0.131 
#> # ℹ 86 more rows