show_uniq gets the unique values of a column and their position within that vector, prints them neatly to the console, then returns the original data frame unchanged. It's just a convenience for showing the values in a column without breaking your workflow or train of thought, and is useful for identifying groups for add_grps.

show_uniq(.data, col)

Arguments

.data

A data frame

col

Bare column name of interest

Value

Original unchanged .data

Examples

# show_uniq makes it easy to see that the values of `ratio` that correspond to
# poverty (ratio of 0 to 0.99)
# are at positions 2:4, and for low-income (ration of 0 to 1.99) are at 2:9
pov_age %>%
  dplyr::mutate(age = forcats::as_factor(age)) %>%
  dplyr::group_by(name, age) %>%
  show_uniq(ratio) %>%
  add_grps(list(pov_determined = 1, poverty = 2:4, low_income = 2:9),
           group = ratio)
#> 
#> 1: Poverty status determined 2: Under .50                 
#> 3: .50 to .74                4: .75 to .99                
#> 5: 1.00 to 1.24              6: 1.25 to 1.49              
#> 7: 1.50 to 1.74              8: 1.75 to 1.84              
#> 9: 1.85 to 1.99              10: 2.00 to 2.99             
#> 11: 3.00 to 3.99             12: 4.00 to 4.99             
#> 13: 5.00 and over           
#> 
#> # A tibble: 390 × 4
#> # Groups:   name, age [130]
#>    name    age            ratio          estimate
#>    <chr>   <fct>          <fct>             <dbl>
#>  1 Bethany Under 6 years  pov_determined      274
#>  2 Bethany Under 6 years  poverty               8
#>  3 Bethany Under 6 years  low_income           55
#>  4 Bethany 6 to 11 years  pov_determined      539
#>  5 Bethany 6 to 11 years  poverty              17
#>  6 Bethany 6 to 11 years  low_income           26
#>  7 Bethany 12 to 17 years pov_determined      446
#>  8 Bethany 12 to 17 years poverty               0
#>  9 Bethany 12 to 17 years low_income           21
#> 10 Bethany 18 to 24 years pov_determined      249
#> # … with 380 more rows