When producing conditional estimates from a regression model, it is often useful to set variables not of interest to their mode when creating the newdata object.

ff_mode(...)

finalfit_mode(...)

Arguments

...

Unquoted factor names.

Value

The most frequent level in a factor.

Examples

library(dplyr)
colon_s %>% 
  summarise(age.factor = ff_mode(age.factor))
#>   age.factor
#> 1  60+ years
  
colon_s %>% 
  select(sex.factor, rx.factor, obstruct.factor, perfor.factor) %>% 
  summarise(across(everything(), ff_mode))
#>   sex.factor rx.factor obstruct.factor perfor.factor
#> 1       Male       Obs              No            No
  
colon_s %>% 
  reframe(across(where(is.factor), ff_mode))
#>    rx sex.factor rx.factor obstruct.factor perfor.factor adhere.factor
#> 1 Obs       Male       Obs              No            No            No
#> 2 Obs       Male       Obs              No            No            No
#> 3 Obs       Male       Obs              No            No            No
#> 4 Obs       Male       Obs              No            No            No
#>   differ.factor extent.factor surg.factor node4.factor status.factor age.factor
#> 1      Moderate        Serosa       Short           No         Alive  60+ years
#> 2      Moderate        Serosa       Short           No         Alive  60+ years
#> 3      Moderate        Serosa       Short           No         Alive  60+ years
#> 4      Moderate        Serosa       Short           No         Alive  60+ years
#>   loccomp.factor mort_5yr   hospital
#> 1             No    Alive hospital_1
#> 2             No    Alive hospital_2
#> 3             No    Alive hospital_4
#> 4             No    Alive hospital_5
  # Note, 4 rows is returned in this example because 4 factor levels within `hospital` 
  # have the same frequency.