# Vector of missing and float

**URL:** https://discourse.julialang.org/t/vector-of-missing-and-float/96311
**Category:** General Usage
**Tags:** question, missing-values
**Created:** [March 19, 2023, 4:07pm UTC](https://discourse.julialang.org/t/vector-of-missing-and-float/96311 "2023-03-19T16:07:52Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![ejlongman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ejlongman/32/36801_2.png) [@ejlongman](https://discourse.julialang.org/u/ejlongman)
#### Post date: [March 19, 2023, 4:07pm UTC](https://discourse.julialang.org/t/vector-of-missing-and-float/96311/1 "2023-03-19T16:07:52Z")

</div>

Hello,

I dropped missing values from a dataframe and then turned a column into a vector. The vector does not have missing values, but it has type:

```julia
7554-element Vector{Union{Missing, Float64}}:

```

This prevents me from using the autocov function. Does anyone know how to convert it to just a vector of only Float64? Filtering missing values again does not drop any observations and it still remains the wrong type:

```julia
inv_nomiss = filter(!ismissing,inv)

```

---

<div class="post-metadata">

### Author: ![liamfdoherty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liamfdoherty/32/24516_2.png) [@liamfdoherty](https://discourse.julialang.org/u/liamfdoherty)
#### Post date: [March 19, 2023, 4:18pm UTC](https://discourse.julialang.org/t/vector-of-missing-and-float/96311/2 "2023-03-19T16:18:10Z")

</div>

Maybe

```julia
inv_nomiss = convert(Vector{Float64}, collect(skipmissing(inv)))

```

?

EDIT: Probably cleaner for you: Once you have `inv_nomiss`, you can just do

```julia
convert(Vector{Float64}, inv_nomiss)

```

so that you aren’t skipping missings in a vector that doesn’t have any.

---

<div class="post-metadata">

### Author: ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)
#### Post date: [March 19, 2023, 4:41pm UTC](https://discourse.julialang.org/t/vector-of-missing-and-float/96311/3 "2023-03-19T16:41:45Z")

</div>

I think you want `disallowmissing` or its in-place version `disallowmissing!`.

```julia
julia> using DataFrames

help?> disallowmissing!
search: disallowmissing! disallowmissing

  disallowmissing!(df::DataFrame, cols=:; error::Bool=true)

  Convert columns cols of data frame df from element type Union{T, Missing} to T to drop support
  for missing values.

  cols can be any column selector (Symbol, string or integer; :, Cols, All, Between, Not, a
  regular expression, or a vector of Symbols, strings or integers).

  If cols is omitted all columns in the data frame are converted.

  If error=false then columns containing a missing value will be skipped instead of throwing an
  error.

  Metadata: this function preserves table-level and column-level :note-style metadata.

```

---

<div class="post-metadata">

### Author: ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)
#### Post date: [March 19, 2023, 10:05pm UTC](https://discourse.julialang.org/t/vector-of-missing-and-float/96311/4 "2023-03-19T22:05:41Z")

</div>

> [@ejlongman](#):
>
> `7554-element Vector{Union{Missing, Float64}}:`
> 
> Does anyone know how to convert it to just a vector of only Float64?

No libraries needed, you can rely on Julia narrowing type on broadcasting:

```julia
julia> A = Union{Int,Missing}[1, 2]
2-element Vector{Union{Missing, Int64}}:
 1
 2

julia> identity.(A)
2-element Vector{Int64}:
 1
 2

```

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [March 19, 2023, 10:52pm UTC](https://discourse.julialang.org/t/vector-of-missing-and-float/96311/5 "2023-03-19T22:52:33Z")

</div>

or

```julia
Float64.(v)

```

to be more explicit about the desired type

---

<div class="post-metadata">

### Author: ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)
#### Post date: [March 20, 2023, 9:49am UTC](https://discourse.julialang.org/t/vector-of-missing-and-float/96311/6 "2023-03-20T09:49:19Z")

</div>

May I also suggest looking into `coalesce()` if you happen have a value you can assign to `missing`?

---

<div class="post-metadata">

### Author: ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)
#### Post date: [March 20, 2023, 10:08am UTC](https://discourse.julialang.org/t/vector-of-missing-and-float/96311/7 "2023-03-20T10:08:40Z")

</div>

also

```julia
float(v)

```

---

<div class="post-metadata">

### Author: ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)
#### Post date: [March 20, 2023, 10:22am UTC](https://discourse.julialang.org/t/vector-of-missing-and-float/96311/8 "2023-03-20T10:22:49Z")

</div>

The end result is the same as some of the ideas above, but I feel like this one does a decent job of communicating (to humans) your intent—to set a new container type rather than operating on elements:

```julia
Float64[inv_nomiss;]

```

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [March 20, 2023, 7:36pm UTC](https://discourse.julialang.org/t/vector-of-missing-and-float/96311/9 "2023-03-20T19:36:30Z")

</div>

> [@rocco\_sprmnt21](#):
>
> `float(v)`

There is no narrowing, the output remains unchanged: `Vector{Union{Missing, Float64}}`

---

<div class="post-metadata">

### Author: ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)
#### Post date: [March 20, 2023, 8:09pm UTC](https://discourse.julialang.org/t/vector-of-missing-and-float/96311/10 "2023-03-20T20:09:44Z")

</div>

Just as you say. I hadn’t done a meaningful test

```julia
julia> v=[1,2,missing]
3-element Vector{Union{Missing, Int64}}:
 1
 2
  missing

julia> float(v)
3-element Vector{Union{Missing, Float64}}:
 1.0
 2.0
  missing

julia> filter!(!ismissing,v)
2-element Vector{Union{Missing, Int64}}:
 1
 2

julia> v
2-element Vector{Union{Missing, Int64}}:
 1
 2

julia> float(v)
2-element Vector{Union{Missing, Float64}}:
 1.0
 2.0

```

I had trusted the first meaning that comes to mind when reading the definition of the function

```julia
 Convert a number or array to a floating point data type.

```

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [March 20, 2023, 8:56pm UTC](https://discourse.julialang.org/t/vector-of-missing-and-float/96311/11 "2023-03-20T20:56:19Z")

</div>

`collect(skipmissing(x))` is probably your best bet.
