Skip to content

Commit

Permalink
Merge pull request #10 from TidierOrg/rdboyes-patch-1
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
rdboyes authored Feb 27, 2024
2 parents 0405447 + 6e50819 commit ddc84b9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
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.
"""

0 comments on commit ddc84b9

Please sign in to comment.