# Queryverse: How to @select columns with specific eltype? (using \`oftype\` function)

**URL:** <https://discourse.julialang.org/t/queryverse-how-to-select-columns-with-specific-eltype-using-oftype-function/28709>\
**Category:** Data\
**Tags:** query, queryverse\
**Created:** [September 13, 2019, 3:56am UTC](https://discourse.julialang.org/t/queryverse-how-to-select-columns-with-specific-eltype-using-oftype-function/28709 "2019-09-13T03:56:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anselm\_Jeong](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anselm_jeong/32/7869_2.png) [@Anselm\_Jeong](https://discourse.julialang.org/u/Anselm_Jeong)\
**Post date:** [September 13, 2019, 3:56am UTC](https://discourse.julialang.org/t/queryverse-how-to-select-columns-with-specific-eltype-using-oftype-function/28709/1 "2019-09-13T03:56:54Z")

</div>

Dear all `Queryverse` users.

In an auxilary package `QueryOperators.NamedTupleUtilities`, there is a helper function named `oftype`. I guess it is related with selecting columns with specific eltype. But I cannot figure out how to use this function.

In the case of very similar function `startswith()`, it can be used easily in the following way…

```julia
df = DataFrame(foo=[1,2,3], bar=[3.0,2.0,1.0], bat=["a","b","c"])

df |> @select(startswith("b")) |> DataFrame

```

It produces result as expected.

```julia
3×2 DataFrame
│ Row │ bar │ bat │
│ │ Float64 │ String │
├─────┼─────────┼────────┤
│ 1 │ 3.0 │ a │

```

However, the following command does not work. It is awkward since the function signatures of these two functions are so similar.

```julia
@generated function startswith(a::NamedTuple{an}, ::Val{bn}) where {an, bn}
@generated function oftype (a::NamedTuple{an}, ::Val{b}) where {an, b}

df |> @select(oftype(Float64)) |> DataFrame

ERROR: ArgumentError: 'QueryOperators.EnumerableMap{NamedTuple{,Tuple{}},QueryOperators.EnumerableIterable{NamedTuple{(:foo, :bar, :bat),Tuple{Int64,Float64,String}},Tables.DataValueRowIterator{NamedTuple{(:foo, :bar, :bat),Tuple{Int64,Float64,String}},Tables.RowIterator{NamedTuple{(:foo, :bar, :bat),Tuple{Array{Int64,1},Array{Float64,1},Array{String,1}}}}}},getfield(Main, Symbol("##158#160"))}' iterates 'NamedTuple{,Tuple{}}' values, which don't satisfy the Tables.jl Row-iterator interface

```

There are other functions in this package(`QueryOperators.NamedTupleUtilities`). It seems that these functions provide functionalities similar to tidyverse’s `select_if` function.

Anyone can help me to master how to use these functions???

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [September 13, 2019, 4:56pm UTC](https://discourse.julialang.org/t/queryverse-how-to-select-columns-with-specific-eltype-using-oftype-function/28709/2 "2019-09-13T16:56:31Z")

</div>

This is broken right now, but I just finished some PRs that should fix this. Will probably take a bit until they are reviewed and we’ve tagged a new release.

Once they are merged, the syntax to use this is `@select(::Number, ::String)` etc.

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [September 13, 2019, 10:57pm UTC](https://discourse.julialang.org/t/queryverse-how-to-select-columns-with-specific-eltype-using-oftype-function/28709/3 "2019-09-13T22:57:00Z")

</div>

Ok, I just released a version of [Query.jl](https://github.com/queryverse/Query.jl) where this now works. Try

```julia
df |> @select(::Float64) |> DataFrame

```

It also works with abstract super types, for example to select all numeric columns (int and float):

```julia
df |> @select(::Number) |> DataFrame

```

---

<div class="post-metadata">

**Author:** ![Anselm\_Jeong](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anselm_jeong/32/7869_2.png) [@Anselm\_Jeong](https://discourse.julialang.org/u/Anselm_Jeong)\
**Post date:** [September 14, 2019, 10:14am UTC](https://discourse.julialang.org/t/queryverse-how-to-select-columns-with-specific-eltype-using-oftype-function/28709/4 "2019-09-14T10:14:47Z")

</div>

Thanks for prompt replies and nice solutions…
