# How to replace all values in an array with missing values?

**URL:** https://discourse.julialang.org/t/how-to-replace-all-values-in-an-array-with-missing-values/75467
**Category:** General Usage
**Tags:** question, arrays, nan, missing-values
**Created:** [January 30, 2022, 2:36pm UTC](https://discourse.julialang.org/t/how-to-replace-all-values-in-an-array-with-missing-values/75467 "2022-01-30T14:36:10Z")
**Posts on this page:** 4
**Page:** 3

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [February 2, 2022, 5:03pm UTC](https://discourse.julialang.org/t/how-to-replace-all-values-in-an-array-with-missing-values/75467/41 "2022-02-02T17:03:54Z")

</div>

Ah thanks for the correction! and sorry for the confusion, I had a wrong model of the memory layout for this kind of arrays (I thought each struct would be stored inline in the array). So here the undefined reference is not in `A` but in the array (so the compiler needs to add a check for `#undef` when accessing the array).

Then it’s better than I thought: it’s easier to check an array is well initialized, than to check initialization of all struct fields.

> In other words, `x.f` or `x[i]` can be undefined but `x` cannot ever be undefined. That’s an significant difference and I’m not sure why you’re trying to insist that it’s no difference at all.

Not sure what you mean: I’m talking about these undefined `x.f` and `x[i]`, not undefined `x`.

The point still stands with “opt out” being available (and to some extent also undefined array elements), though not as strongly as I thought.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [February 2, 2022, 5:16pm UTC](https://discourse.julialang.org/t/how-to-replace-all-values-in-an-array-with-missing-values/75467/42 "2022-02-02T17:16:01Z")

</div>

> [@sijo](#):
>
> Not sure what you mean: I’m talking about these undefined `x.f` and `x[i]` , not undefined `x` .

The distinction is this: in Java, say, you can have an object reference `x` which, rather than being an instance of the type you want is `null`. That cannot happen in Julia: if you have `x` then it’s not null/undef. (There are undefined variables but that’s a different thing altogether.)

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [February 2, 2022, 5:33pm UTC](https://discourse.julialang.org/t/how-to-replace-all-values-in-an-array-with-missing-values/75467/43 "2022-02-02T17:33:36Z")

</div>

Ah yes it’s great that you cannot pass `#undef` around, no disagreement here as I wrote above:

> I agree having no null _value_ is a huge improvement, it makes it much less likely to have an “undefined reference” exception in practice.

---

<div class="post-metadata">

### Author: ![JonathanLilly](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonathanlilly/32/49070_2.png) [@JonathanLilly](https://discourse.julialang.org/u/JonathanLilly)
#### Post date: [April 15, 2023, 12:24pm UTC](https://discourse.julialang.org/t/how-to-replace-all-values-in-an-array-with-missing-values/75467/44 "2023-04-15T12:24:26Z")

</div>

Wow, thanks for this very informative explanation!

[Previous page](https://discourse.julialang.org/t/how-to-replace-all-values-in-an-array-with-missing-values/75467.md?page=2)
