inspect_cat | R Documentation |
For a single dataframe, summarise the levels of each categorical column. If two dataframes are supplied, compare the levels of categorical features that appear in both dataframes. For grouped dataframes, summarise the levels of categorical features separately for each group.
inspect_cat(df1, df2 = NULL, include_int = FALSE)
df1 |
A dataframe. |
df2 |
An optional second data frame for comparing categorical levels.
Defaults to |
include_int |
Logical flag - whether to treat integer columns as categories. Default is |
For a single dataframe, the tibble returned contains the columns:
col_name
, character vector containing column names of df1
.
cnt
integer column containing count of unique levels found in each column,
including NA
.
common
, a character column containing the name of the most common level.
common_pcnt
, the percentage of each column occupied by the most common level shown in
common
.
levels
, a named list containing relative frequency tibbles for each feature.
For a pair of dataframes, the tibble returned contains the columns:
col_name
, character vector containing names of columns appearing in both
df1
and df2
.
jsd
, a numeric column containing the Jensen-Shannon divergence. This measures the
difference in relative frequencies of levels in a pair of categorical features. Values near
to 0 indicate agreement of the distributions, while 1 indicates disagreement.
pval
, the p-value corresponding to a NHT that the true frequencies of the categories are equal.
A small p indicates evidence that the the two sets of relative frequencies are actually different. The test
is based on a modified Chi-squared statistic.
lvls_1
, lvls_2
, the relative frequency of levels in each of df1
and df2
.
For a grouped dataframe, the tibble returned is as for a single dataframe, but where
the first k
columns are the grouping columns. There will be as many rows in the result
as there are unique combinations of the grouping variables.
A tibble summarising or comparing the categorical features in one or a pair of dataframes.
Alastair Rushworth
inspect_imb
, show_plot
# Load dplyr for starwars data & pipe library(dplyr) # Single dataframe summary inspect_cat(starwars) # Paired dataframe comparison inspect_cat(starwars, starwars[1:20, ]) # Grouped dataframe summary starwars %>% group_by(gender) %>% inspect_cat()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.