# Julian way to "remove" missing type in the eltype of a Matrix?

**URL:** <https://discourse.julialang.org/t/julian-way-to-remove-missing-type-in-the-eltype-of-a-matrix/83168>\
**Category:** General Usage\
**Tags:** dataframes, missing-values\
**Created:** [June 22, 2022, 8:33am UTC](https://discourse.julialang.org/t/julian-way-to-remove-missing-type-in-the-eltype-of-a-matrix/83168 "2022-06-22T08:33:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [June 22, 2022, 8:33am UTC](https://discourse.julialang.org/t/julian-way-to-remove-missing-type-in-the-eltype-of-a-matrix/83168/1 "2022-06-22T08:33:13Z")

</div>

```julia
julia> A = [1 2 missing; 4 5 6]
2×3 Matrix{Union{Missing, Int64}}:
 1 2 missing
 4 5 6

julia> A[1,3] = 3
3

julia> A
2×3 Matrix{Union{Missing, Int64}}:
 1 2 3
 4 5 6

```

Now, I want to get rid of the `missing` in the eltype and just get `Matrix{Int64}`.

I can get the `nonmissingtype` of the eltype and manually convert, or use `disallowmissings` from `DataFrames`, but the first is ugly, the second is not in base.

Other ways? Or could simply `disallowmissing` (and of course `allowmissing`) be implemented in `Base`, as they are useful not only for DataFrames…

---

<div class="post-metadata">

**Author:** ![JM\_Beckers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jm_beckers/32/22482_2.png) [@JM\_Beckers](https://discourse.julialang.org/u/JM_Beckers)\
**Post date:** [June 22, 2022, 8:37am UTC](https://discourse.julialang.org/t/julian-way-to-remove-missing-type-in-the-eltype-of-a-matrix/83168/2 "2022-06-22T08:37:24Z")

</div>

```julia
A=convert(Array{Int}, A)

```

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [June 22, 2022, 8:39am UTC](https://discourse.julialang.org/t/julian-way-to-remove-missing-type-in-the-eltype-of-a-matrix/83168/3 "2022-06-22T08:39:33Z")

</div>

```julia
julia> using Missings

julia> disallowmissing(A)
2×3 Matrix{Int64}:
 1 2 3
 4 5 6

```

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [June 22, 2022, 8:41am UTC](https://discourse.julialang.org/t/julian-way-to-remove-missing-type-in-the-eltype-of-a-matrix/83168/4 "2022-06-22T08:41:20Z")

</div>

yes, but you first need to know that the eltype is indeed `Int`.

In general you can do `convert(Array{nonmissingtype(eltype(A)),ndims(A)}, A)` but it’s ugly…

---

<div class="post-metadata">

**Author:** ![JM\_Beckers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jm_beckers/32/22482_2.png) [@JM\_Beckers](https://discourse.julialang.org/u/JM_Beckers)\
**Post date:** [June 22, 2022, 8:42am UTC](https://discourse.julialang.org/t/julian-way-to-remove-missing-type-in-the-eltype-of-a-matrix/83168/5 "2022-06-22T08:42:37Z")

</div>

Yep, I missed the point that you do not know the `nonmissingtype` of the eltype

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [June 22, 2022, 8:42am UTC](https://discourse.julialang.org/t/julian-way-to-remove-missing-type-in-the-eltype-of-a-matrix/83168/6 "2022-06-22T08:42:40Z")

</div>

Thanks, I didn’t think about `Missings.jl`… still would be useful having it in `Base`…

---

<div class="post-metadata">

**Author:** ![Jollywatt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jollywatt/32/202198_2.png) [@Jollywatt](https://discourse.julialang.org/u/Jollywatt)\
**Post date:** [June 22, 2022, 8:47am UTC](https://discourse.julialang.org/t/julian-way-to-remove-missing-type-in-the-eltype-of-a-matrix/83168/7 "2022-06-22T08:47:05Z")

</div>

```julia
julia> A
2×3 Matrix{Union{Missing, Int64}}:
 1 2 3
 4 5 6

julia> identity.(A) # or map(identity, A)
2×3 Matrix{Int64}:
 1 2 3
 4 5 6

```

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [June 22, 2022, 8:48am UTC](https://discourse.julialang.org/t/julian-way-to-remove-missing-type-in-the-eltype-of-a-matrix/83168/8 "2022-06-22T08:48:30Z")

</div>

yes - you can also do `identity.(A)`. The difference is that `disallowmissing(A)` is a no-op, if `A` already does not allow missing values, while `map` or broadcast always allocates a new object.
