diff --git a/README.md b/README.md index d4c3471..928a7b8 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ `TidierCats.jl `is a 100% Julia implementation of the R forcats package. -`TidierCats.jl` has one main goal: to implement forcats's straightforward syntax and of ease of use while working with categorical variables for Julia users. While this package was develeoped to work seamelessly with `Tidier.jl` fucntions and macros, it can also work as a indepentenly as a standalone package. This package is powered by CateogricalArrays.jl +`TidierCats.jl` has one main goal: to implement forcats's straightforward syntax and of ease of use while working with categorical variables for Julia users. While this package was develeoped to work seamelessly with `Tidier.jl` functions and macros, it can also work as a independently as a standalone package. This package is powered by CateogricalArrays.jl. ## What functions does TidierCats.jl support? @@ -228,7 +228,7 @@ end ``` #### `cat_lump_min()` -This function wil lump any cargory with less than the minimum number of entries and recateogrize it as "Other" as the default, or a category name chosen by the user. +This function wil lump any category with less than the minimum number of entries and recategorize it as "Other" (the default), or a category name chosen by the user. ```julia lumpedbymin = @chain df begin @@ -246,7 +246,7 @@ print(levels(lumpedbymin[!,:CatVar])) #### `cat_lump_prop()` -This function wil lump any cargory with less than the minimum proportion and recateogrize it as "Other" as the default, or a category name chosen by the user. +This function wil lump all categories with less than the minimum proportion and recateogrize it as "Other" (the default), or a category name chosen by the user. ```julia lumpedbyprop = @chain df begin diff --git a/docs/examples/UserGuide/supported_functions.jl b/docs/examples/UserGuide/supported_functions.jl index a04f2ce..d62cd7a 100644 --- a/docs/examples/UserGuide/supported_functions.jl +++ b/docs/examples/UserGuide/supported_functions.jl @@ -155,12 +155,4 @@ print(levels(df.CatVar)) # and -print(levels(lumpedbyprop.CatVar)) - - -# ## `cat_na_value_to_level()` -# This function will replace any missing values in a categorical array with "Missing" to make sure they appear on plots. - -#x = categorical([missing, "A", "B", missing, "A"]) -#cat_na_value_to_level(x) -#print(levels(x)) \ No newline at end of file +print(levels(lumpedbyprop.CatVar)) \ No newline at end of file diff --git a/src/TidierCats.jl b/src/TidierCats.jl index 9967a94..8efb544 100644 --- a/src/TidierCats.jl +++ b/src/TidierCats.jl @@ -7,7 +7,8 @@ using Reexport @reexport using CategoricalArrays -export cat_rev, cat_relevel, cat_infreq, cat_lump, cat_reorder, cat_collapse, cat_lump_min, cat_lump_prop, as_categorical +export cat_rev, cat_relevel, cat_infreq, cat_lump, cat_reorder, cat_collapse, cat_lump_min, cat_lump_prop +export as_categorical, as_integer include("catsdocstrings.jl") """ @@ -176,4 +177,15 @@ function cat_lump_prop(cat_array, prop::Float64, other_level::String = "Other") return new_cat_array end +""" +$docstring_as_integer +""" +function as_integer(cat_value::CategoricalValue) + return CategoricalArrays.levelcode(cat_value) +end + +function as_integer(cat_array::CategoricalArray) + return CategoricalArrays.levelcode.(cat_array) +end + end diff --git a/src/catsdocstrings.jl b/src/catsdocstrings.jl index 2cad118..0f12688 100644 --- a/src/catsdocstrings.jl +++ b/src/catsdocstrings.jl @@ -313,3 +313,7 @@ julia> cat_lump_prop(cat_array, 0.3) "Other" ``` """ +const docstring_as_integer = +""" +Converts a CategoricalValue or CategoricalArray to an integer or vector of integers. +""" \ No newline at end of file