# DataFrames, get a subset in which the value of a particular column is not missing

**URL:** <https://discourse.julialang.org/t/dataframes-get-a-subset-in-which-the-value-of-a-particular-column-is-not-missing/71680>\
**Category:** General Usage\
**Tags:** dataframes, dataframesmeta\
**Created:** [November 17, 2021, 8:01pm UTC](https://discourse.julialang.org/t/dataframes-get-a-subset-in-which-the-value-of-a-particular-column-is-not-missing/71680 "2021-11-17T20:01:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![doomphoenix-qxz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/doomphoenix-qxz/32/7009_2.png) [@doomphoenix-qxz](https://discourse.julialang.org/u/doomphoenix-qxz)\
**Post date:** [November 17, 2021, 8:01pm UTC](https://discourse.julialang.org/t/dataframes-get-a-subset-in-which-the-value-of-a-particular-column-is-not-missing/71680/1 "2021-11-17T20:01:57Z")

</div>

I’m probably doing something dumb here, but I have a DataFrame and I want to get all rows for which a particular column (which is called `:Level` and is type `Union{Int, Missing}`) is not `missing`. My first two tries (using DataFramesMeta.jl) haven’t worked:

```julia
julia> standards = @subset(df, filter(x->true,skipmissing(:Level)))
ERROR: ArgumentError: length 10 of vector returned from function #478 is different from number of rows 20 of the source data frame.
# Long stacktrace that doesn't seem relevant here

julia> standards = @subset(df, !.(ismissing.(:Level)))
ERROR: syntax: invalid identifier name "."
Stacktrace:
 [1] top-level scope
   @ none:1

```

What am I `missing` (pun intended)?

---

<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:** [November 17, 2021, 8:09pm UTC](https://discourse.julialang.org/t/dataframes-get-a-subset-in-which-the-value-of-a-particular-column-is-not-missing/71680/2 "2021-11-17T20:09:21Z")

</div>

You can do `@rsubset` for row-wise operatoins

```julia
julia> using DataFramesMeta

julia> df = DataFrame(Level = [1, 2, missing, 4]);

julia> @rsubset df !ismissing(:Level)
3×1 DataFrame
 Row │ Level  
     │ Int64? 
─────┼────────
   1 │ 1
   2 │ 2
   3 │ 4

```

The first one errors because the returned value from a `@subset` operation has to be a boolean vector of the same length as the original data frame.

In the second one, you have problems with the broadcasting syntax, try

```julia
julia> @subset df (!).(ismissing.(:Level))
3×1 DataFrame
 Row │ Level  
     │ Int64? 
─────┼────────
   1 │ 1
   2 │ 2
   3 │ 4

```

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [November 17, 2021, 8:12pm UTC](https://discourse.julialang.org/t/dataframes-get-a-subset-in-which-the-value-of-a-particular-column-is-not-missing/71680/3 "2021-11-17T20:12:33Z")

</div>

another option is just:

`subdf = df[.! ismissing.(df.Level),:]`

---

<div class="post-metadata">

**Author:** ![doomphoenix-qxz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/doomphoenix-qxz/32/7009_2.png) [@doomphoenix-qxz](https://discourse.julialang.org/u/doomphoenix-qxz)\
**Post date:** [November 17, 2021, 8:37pm UTC](https://discourse.julialang.org/t/dataframes-get-a-subset-in-which-the-value-of-a-particular-column-is-not-missing/71680/4 "2021-11-17T20:37:40Z")

</div>

All of these work. Thanks to both! I think I’ll mark pdeffebach’s answer because it’s first. Thanks again!
