# How to filter out rows with NaN in specific fields?

**URL:** <https://discourse.julialang.org/t/how-to-filter-out-rows-with-nan-in-specific-fields/30250>\
**Category:** New to Julia\
**Tags:** dataframes\
**Created:** [October 23, 2019, 10:50pm UTC](https://discourse.julialang.org/t/how-to-filter-out-rows-with-nan-in-specific-fields/30250 "2019-10-23T22:50:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abe/32/8911_2.png) [@abe](https://discourse.julialang.org/u/abe)\
**Post date:** [October 23, 2019, 10:50pm UTC](https://discourse.julialang.org/t/how-to-filter-out-rows-with-nan-in-specific-fields/30250/1 "2019-10-23T22:50:05Z")

</div>

This seems like a pretty basic operation, but I’m having difficulty figuring it out. In dplyr I’d do something like filtering based on !is.na(my\_field), but I’m not sure what the equivalent Julia/DataFramesMeta is. I have @linq statements, and I’ve tried a variety of solutions (like filtering out missing) which haven’t worked. How can I filter out rows with NaN in specific fields within my linq statements?

Thank you!

---

<div class="post-metadata">

**Author:** ![ElOceanografo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eloceanografo/32/624_2.png) [@ElOceanografo](https://discourse.julialang.org/u/ElOceanografo)\
**Post date:** [October 24, 2019, 12:04am UTC](https://discourse.julialang.org/t/how-to-filter-out-rows-with-nan-in-specific-fields/30250/2 "2019-10-24T00:04:24Z")

</div>

You’re looking for `isnan`:

```julia
using DataFrames
x = randn(10)
x[5] = NaN
df = DataFrame(x=x)

filter(row -> ! isnan(row.x), df)

```

Or, using DataFramesMeta,

```julia
using DataFramesMeta
@where(df, .! isnan.(:x))
@linq df |> where(.! isnan.(:x))

```

In Julia, `missing` is the equivalent of R’s `NA`, and is used for any value which exist in theory but are not available or weren’t measured. In contrast `NaN` (not-a-number) only exists for Floats. For most data analysis, `missing` is more generic and will be easier to work with in Julia–depending on your workflow, it might make sense to convert `NaN`s to `missing`s first.

(For more than you (probably) want to know on this topic, please [this blog post](https://julialang.org/blog/2018/06/missing) and this [Discourse discussion](https://discourse.julialang.org/t/missing-or-nan/12729)… 🙃)

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [October 24, 2019, 5:35am UTC](https://discourse.julialang.org/t/how-to-filter-out-rows-with-nan-in-specific-fields/30250/3 "2019-10-24T05:35:16Z")

</div>

Here’s a way if you want to remove rows with NaN’s in any field:

```julia
filter!(isfinite ∘ sum, df)

```
