Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add percentage and default sorting to miss_scan_count (Fix #341) #347

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tranlevantra
Copy link

@tranlevantra tranlevantra commented Dec 13, 2024

Description

This PR updates miss_scan_count():

  • A new column pct that shows the percentage of matches per column.

  • Default sorting of results in descending order by count (n).

  • Unified logic for handling both single and multiple search terms using paste0() and grepl functions.

Related Issue

Fix #341

Example

dat_ms <- tibble::tribble(~x,  ~y,    ~z,  ~specials,
                          1,   "A",   -100, "?",
                          3,   "N/A", -99,  "!",
                          NA,  NA,    -98,  ".",
                          -99, "E",   -101, "*",
                          -98, "F",   -1,  "-")

miss_scan_count(dat_ms,-99)
#> # A tibble: 4 × 3
#>   Variable     n   pct
#>   <chr>    <int> <dbl>
#> 1 x            1    20
#> 2 z            1    20
#> 3 y            0     0
#> 4 specials     0     0

miss_scan_count(dat_ms,c(-99,-98))
#> # A tibble: 4 × 3
#>   Variable     n   pct
#>   <chr>    <int> <dbl>
#> 1 x            2    40
#> 2 z            2    40
#> 3 y            0     0
#> 4 specials     0     0

miss_scan_count(dat_ms,c("-99","-98","N/A"))
#> # A tibble: 4 × 3
#>   Variable     n   pct
#>   <chr>    <int> <dbl>
#> 1 x            2    40
#> 2 z            2    40
#> 3 y            1    20
#> 4 specials     0     0

miss_scan_count(dat_ms, "\\?")
#> # A tibble: 4 × 3
#>   Variable     n   pct
#>   <chr>    <int> <dbl>
#> 1 specials     1    20
#> 2 x            0     0
#> 3 y            0     0
#> 4 z            0     0

miss_scan_count(dat_ms, "\\!")
#> # A tibble: 4 × 3
#>   Variable     n   pct
#>   <chr>    <int> <dbl>
#> 1 specials     1    20
#> 2 x            0     0
#> 3 y            0     0
#> 4 z            0     0

miss_scan_count(dat_ms, "\\.")
#> # A tibble: 4 × 3
#>   Variable     n   pct
#>   <chr>    <int> <dbl>
#> 1 specials     1    20
#> 2 x            0     0
#> 3 y            0     0
#> 4 z            0     0

miss_scan_count(dat_ms, "\\*")
#> # A tibble: 4 × 3
#>   Variable     n   pct
#>   <chr>    <int> <dbl>
#> 1 specials     1    20
#> 2 x            0     0
#> 3 y            0     0
#> 4 z            0     0

miss_scan_count(dat_ms, "-")
#> # A tibble: 4 × 3
#>   Variable     n   pct
#>   <chr>    <int> <dbl>
#> 1 z            5   100
#> 2 x            2    40
#> 3 specials     1    20
#> 4 y            0     0

Created on 2024-12-14 with reprex v2.1.1

Tests

test-miss-scan-count was updated accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

miss_scan_count should contain percentage information and default to descending order
1 participant