# Assignment of a \`missing\` value fails in DataFrames 0.11.1

**URL:** <https://discourse.julialang.org/t/assignment-of-a-missing-value-fails-in-dataframes-0-11-1/7379>\
**Category:** Data\
**Created:** [November 29, 2017, 4:42am UTC](https://discourse.julialang.org/t/assignment-of-a-missing-value-fails-in-dataframes-0-11-1/7379 "2017-11-29T04:42:09Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [November 29, 2017, 3:42pm UTC](https://discourse.julialang.org/t/assignment-of-a-missing-value-fails-in-dataframes-0-11-1/7379/10 "2017-11-29T15:42:51Z")

</div>

> [@pdeffebach](#):
>
> I would have to create a new column just to use the command replace x = Missing if x \< 0?

Well, in R you always create new columns, so it’s not completely unreasonable. You’d just do something like this:

```julia
df[:x] = ifelse.(df[:x] .< 0, missing, df[:x])

```

or if you want to hardcode the list of missing levels for safety:

```julia
using CategoricalArrays
df[:x] = recode(df[:x], -1 => missing, -2 => missing)

```

Of course, higher-level frameworks like Query or DataFramesMeta will allow you to do this with a nicer syntax.

EDIT: The `recode` solution currently does not work, as the returned array is allowed to contain only missing values. That could be improved. See [Add special case for single missing RHS in recode() by nalimilan · Pull Request #103 · JuliaData/CategoricalArrays.jl · GitHub](https://github.com/JuliaData/CategoricalArrays.jl/pull/103).

---

_[View the full topic](https://discourse.julialang.org/t/assignment-of-a-missing-value-fails-in-dataframes-0-11-1/7379)._
