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

Update README.md #10

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 1 addition & 9 deletions docs/examples/UserGuide/supported_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
print(levels(lumpedbyprop.CatVar))
14 changes: 13 additions & 1 deletion src/TidierCats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

"""
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/catsdocstrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Loading