Skip to content

Commit

Permalink
Document how to turn missing values into normal values (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan authored Dec 28, 2021
1 parent de99bef commit 198d7ff
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/src/using.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,32 @@ julia> levels!(y, ["Young", "Middle"]; allowmissing=true)
```

Conversely, all missing values can be turned into a "normal" value using `replace`
(or `recode`, whose syntax is identical for this operation):
```jldoctest using
julia> replace(y, missing => "missing value")
4-element CategoricalArray{String,1,UInt32}:
"missing value"
"Young"
"Middle"
"Young"
```
Note that the returned array no longer allows for missing values (which is usually what is expected).
This syntax works for array types other than `CategoricalArray`.

An in-place variant `replace!` (respectively `recode!`) is also provided. Note that `y` still allows
for missing values (since the type of an object cannot be changed).
```jldoctest using
julia> replace!(y, missing => "missing value");
julia> y
4-element CategoricalArray{Union{Missing, String},1,UInt32}:
"missing value"
"Young"
"Middle"
"Young"
```

## Combining levels

Some operations imply combining levels of two categorical arrays: this is the case when concatenating arrays (`vcat`, `hcat` and `cat`) and when assigning a `CategoricalValue` from another categorical array.
Expand Down

0 comments on commit 198d7ff

Please sign in to comment.