Count different events in an fhx object

count_event_position(
  x,
  injury_event = FALSE,
  position,
  drop_unknown = FALSE,
  groupby
)

Arguments

x

An fhx object.

injury_event

Optional boolean indicating whether injuries should be considered an "event". Default is FALSE.

position

Depreciated. This allowed users to specify which intra-ring positions to include in the summary output table. The default counts all types of event positions.

drop_unknown

Boolean. Defaults to FALSE. If TRUE will remove the "unknown_fs" and/or "unknown_fi" from rec_type.

groupby

Optional named list containing character vectors that are used to count the total number of different event types. The names given to each character vector give the group's name in the output data frame.

Value

A data frame with a columns giving the event or event group and values giving the corresponding count for each event type or group.

See also

Examples

data(pgm)
count_event_position(pgm)
#> # A tibble: 5 × 3
#>   event      count   prop
#>   <fct>      <int>  <dbl>
#> 1 unknown_fs    17 0.370 
#> 2 dormant_fs    15 0.326 
#> 3 middle_fs     10 0.217 
#> 4 early_fs       3 0.0652
#> 5 late_fs        1 0.0217

# As above, but considering injuries to be a type of event.
count_event_position(pgm, injury_event = TRUE)
#> # A tibble: 6 × 3
#>   event      count  prop
#>   <fct>      <int> <dbl>
#> 1 unknown_fs    17  0.34
#> 2 dormant_fs    15  0.3 
#> 3 middle_fs     10  0.2 
#> 4 unknown_fi     4  0.08
#> 5 early_fs       3  0.06
#> 6 late_fs        1  0.02

# Often we only quantify known intra-ring positions.
# Remove the "unknown_fs" and/or "unknown_fi" with
count_event_position(pgm, drop_unknown = TRUE)
#> # A tibble: 4 × 3
#>   event      count   prop
#>   <fct>      <int>  <dbl>
#> 1 dormant_fs    15 0.517 
#> 2 middle_fs     10 0.345 
#> 3 early_fs       3 0.103 
#> 4 late_fs        1 0.0345

# Using custom "groupby" args in a named list, as
grplist <- list(
  foo = c("dormant_fs", "early_fs"),
  bar = c("middle_fs", "late_fs")
)
count_event_position(pgm, groupby = grplist)
#> # A tibble: 3 × 3
#>   event      count  prop
#>   <fct>      <int> <dbl>
#> 1 foo           18 0.391
#> 2 unknown_fs    17 0.370
#> 3 bar           11 0.239
# Note that if a position in the groupby list is
# not included in rec_type, forcats::fct_count()
# will throw a flag for an "Unknown levels in 'f':"