get_tt_param: Get a parameter value from a summary table

get_tt_paramR Documentation

Get a parameter value from a summary table

Description

The get_tt_param() function can help you to obtain a single parameter value from a summary table generated by the ⁠tt_*()⁠ functions tt_summary_stats(), tt_string_info(), tt_tbl_dims(), or tt_tbl_colnames(). The following parameters are to be used depending on the input tbl:

  • from tt_summary_stats(): "min", "p05", "q_1", "med", "q_3", "p95", "max", "iqr", "range"

  • from tt_string_info(): "length_mean", "length_min", "length_max"

  • from tt_tbl_dims(): "rows", "columns"

  • from tt_tbl_colnames(): any integer present in the .param. column

The tt_summary_stats() and tt_string_info() functions will generate summary tables with columns that mirror the numeric and character columns in their input tables, respectively. For that reason, a column name must be supplied to the column argument in get_tt_param().

Usage

get_tt_param(tbl, param, column = NULL)

Arguments

tbl

Summary table generated by specific transformer functions

⁠obj:<tbl_*>⁠ // required

A summary table generated by either of the tt_summary_stats(), tt_string_info(), tt_tbl_dims(), or tt_tbl_colnames() functions.

param

Parameter name

⁠scalar<character>⁠ // required

The parameter name associated to the value that is to be gotten. These parameter names are always available in the first column (.param.) of a summary table obtained by tt_summary_stats(), tt_string_info(), tt_tbl_dims(), or tt_tbl_colnames().

column

The target column

⁠scalar<character>⁠ // required (in select cases)

The column in the summary table for which the data value should be obtained. This must be supplied for summary tables generated by tt_summary_stats() and tt_string_info() (the tt_tbl_dims() and tt_tbl_colnames() functions will always generate a two-column summary table).

Value

A scalar value.

Examples

Get summary statistics for the first quarter of the game_revenue dataset that's included in the pointblank package.

stats_tbl <- 
  game_revenue %>%
  tt_time_slice(slice_point = 0.25) %>%
  tt_summary_stats()
  
stats_tbl
#> # A tibble: 9 x 3
#>   .param. item_revenue session_duration
#>   <chr>          <dbl>            <dbl>
#> 1 min             0.02              5.1
#> 2 p05             0.03             11  
#> 3 q_1             0.08             17.2
#> 4 med             0.28             28.3
#> 5 q_3             1.37             32  
#> 6 p95            40.0              37.1
#> 7 max           143.               41  
#> 8 iqr             1.28             14.8
#> 9 range         143.               35.9

Sometimes you need a single value from the table generated by the tt_summary_stats() function. For that, we can use the get_tt_param() function. So if we wanted to test whether the maximum session duration during the rest of the time period (the remaining 0.75) is never higher than that of the first quarter of the year, we can supply a value from stats_tbl to test_col_vals_lte():

game_revenue %>%
  tt_time_slice(
    slice_point = 0.25,
    keep = "right"
  ) %>%
  test_col_vals_lte(
    columns = session_duration, 
    value = get_tt_param(
      tbl = stats_tbl,
      param = "max",
      column = "session_duration"
    )
  )
#> [1] TRUE

Function ID

12-7

See Also

Other Table Transformers: tt_string_info(), tt_summary_stats(), tt_tbl_colnames(), tt_tbl_dims(), tt_time_shift(), tt_time_slice()


pointblank documentation built on Oct. 30, 2024, 9:29 a.m.