# How to convert a column of a dataframe to an array of Float64

**URL:** <https://discourse.julialang.org/t/how-to-convert-a-column-of-a-dataframe-to-an-array-of-float64/11393>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 3, 2018, 6:05pm UTC](https://discourse.julialang.org/t/how-to-convert-a-column-of-a-dataframe-to-an-array-of-float64/11393 "2018-06-03T18:05:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 3, 2018, 6:05pm UTC](https://discourse.julialang.org/t/how-to-convert-a-column-of-a-dataframe-to-an-array-of-float64/11393/1 "2018-06-03T18:05:10Z")

</div>

I have a one dimensional array of the following type:  
5001-element Array{Union{Float64, Missings.Missing},1}

I want to convert it into a pure Float64 array to be able to process it with the function Statsbase.crosscor . How can I achieve that?  
Missing values should be replaced with NaN.

Thanks for your replies!

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 3, 2018, 6:19pm UTC](https://discourse.julialang.org/t/how-to-convert-a-column-of-a-dataframe-to-an-array-of-float64/11393/2 "2018-06-03T18:19:17Z")

</div>

Something like

```julia
v = [rand() > 0.90 ? missing : rand() for i in 1:10^4]
g(x) = x === missing ? NaN: x
g.(v)

```

perhaps?

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [June 3, 2018, 6:36pm UTC](https://discourse.julialang.org/t/how-to-convert-a-column-of-a-dataframe-to-an-array-of-float64/11393/3 "2018-06-03T18:36:18Z")

</div>

In 0.7 you can just do

```julia
replace(df[col], missing=>NaN)

```

It’ll even know to change the array type to `Vector{Float64}`, which I was impressed with.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 3, 2018, 6:37pm UTC](https://discourse.julialang.org/t/how-to-convert-a-column-of-a-dataframe-to-an-array-of-float64/11393/4 "2018-06-03T18:37:38Z")

</div>

Fixed a typo:

> [@kristoffer.carlsson](#):
>
> using Missings  
> g(x) = x === Missing ? NaN: x  
> g.(v)

Works like a charm!  
Thank you!
