# Subset using symbol from function input

**URL:** <https://discourse.julialang.org/t/subset-using-symbol-from-function-input/74806>\
**Category:** Data\
**Tags:** dataframes\
**Created:** [January 18, 2022, 2:23pm UTC](https://discourse.julialang.org/t/subset-using-symbol-from-function-input/74806 "2022-01-18T14:23:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frankiewaang](https://avatars.discourse-cdn.com/v4/letter/f/f9ae1b/32.png) [@Frankiewaang](https://discourse.julialang.org/u/Frankiewaang)\
**Post date:** [January 18, 2022, 2:23pm UTC](https://discourse.julialang.org/t/subset-using-symbol-from-function-input/74806/1 "2022-01-18T14:23:23Z")

</div>

Hi Guys,  
I’m a newbie to use Julia for data manipulation. When I try to convert some of my Python `Pandas` code to Julia code, I got some problem.

```julia
function remove_outliers(data::DataFrame,variable::Symbol;lower=-Inf,upper=Inf)
      return subset(data, variable => x -> x .> lower, variable => x -> x .<= upper)

```

This function works perfect but when I try to use `DataFramesMeta` package to do it

```julia
function remove_outliers(data::DataFrame,variable::Symbol;lower=-Inf,upper=Inf)
      return @subset(data, variable .> lower, variable .<= upper)

```

I got some error message. Could anyone help me!

---

<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:** [January 18, 2022, 2:46pm UTC](https://discourse.julialang.org/t/subset-using-symbol-from-function-input/74806/2 "2022-01-18T14:46:35Z")

</div>

You need to escape the `Symbol` with `$`

```julia
@subset(data, $variable .> lower, $variable .<= upper)

```

See the docs [here](https://juliadata.github.io/DataFramesMeta.jl/stable/#dollar).

also, to avoid using `.` everywhere for broadcasting, there is `@rsubset` for row-wise operations. See docs [here](https://juliadata.github.io/DataFramesMeta.jl/stable/#Row-wise-transformations-with-@byrow-and-@rtransform/@rselect/etc.).

---

<div class="post-metadata">

**Author:** ![Frankiewaang](https://avatars.discourse-cdn.com/v4/letter/f/f9ae1b/32.png) [@Frankiewaang](https://discourse.julialang.org/u/Frankiewaang)\
**Post date:** [January 18, 2022, 3:01pm UTC](https://discourse.julialang.org/t/subset-using-symbol-from-function-input/74806/3 "2022-01-18T15:01:02Z")

</div>

Thanks! I like the community so much 🥰

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [January 18, 2022, 3:03pm UTC](https://discourse.julialang.org/t/subset-using-symbol-from-function-input/74806/4 "2022-01-18T15:03:58Z")

</div>

Or just write

```julia
remove_outliers(df, v; lo = -Inf, hi = Inf) = df[lo .< df[!, v] .< hi, :]

```

---

<div class="post-metadata">

**Author:** ![Frankiewaang](https://avatars.discourse-cdn.com/v4/letter/f/f9ae1b/32.png) [@Frankiewaang](https://discourse.julialang.org/u/Frankiewaang)\
**Post date:** [January 19, 2022, 3:52am UTC](https://discourse.julialang.org/t/subset-using-symbol-from-function-input/74806/5 "2022-01-19T03:52:26Z")

</div>

That’s dope!
