ropensci / skimr

A frictionless, pipeable approach to dealing with summary statistics
https://docs.ropensci.org/skimr
1.11k stars 79 forks source link

Guidance on how to create alternate to skimr::top_counts. - skimr::bottom_counts #598

Closed dineshj3d closed 4 years ago

dineshj3d commented 4 years ago

For my data management work, having a peak at the bottom counts would be just as useful as top counts. Looking for guidance how to accomplish via sfl function. Any help appreciated.

elinw commented 4 years ago

First you have to create your function bottom_counts(). Then you would add it to the sfl for factor. You could take a look at the function code for top_counts() and modify it to get the lowest.

dineshj3d commented 4 years ago

Thank you. - will create a new function modeled on top_counts. Not sure how to call the function via sfl (have reviewed the documentation). Appreciate any pointers. Thanks again. top_counts <- function(x, max_char = 3, max_levels = 4) { counts <- sorted_count(x) if (length(counts) > max_levels) { top <- counts[seq_len(max_levels)] } else { top <- counts } top_names <- substr(names(top), 1, max_char) paste0(top_names, ": ", top, collapse = ", ") }

elinw commented 4 years ago
my_skim <- skim_with(factor = sfl(bottom_counts = bottom_counts))

From the example in the Using Skimmer vignette.

elinw commented 4 years ago

This issue is not really an issue report. The best places to get help are probably StackOverflow and Twitter (#rstats)

dineshj3d commented 4 years ago

Understood. Thanks for the recommendation. Appreciate the help.