# Questions about filter and broadcast

**URL:** <https://discourse.julialang.org/t/questions-about-filter-and-broadcast/88520>\
**Category:** New to Julia\
**Tags:** question, dataframes\
**Created:** [October 10, 2022, 12:47pm UTC](https://discourse.julialang.org/t/questions-about-filter-and-broadcast/88520 "2022-10-10T12:47:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhangchunyong](https://avatars.discourse-cdn.com/v4/letter/z/d9b06d/32.png) [@zhangchunyong](https://discourse.julialang.org/u/zhangchunyong)\
**Post date:** [October 10, 2022, 12:47pm UTC](https://discourse.julialang.org/t/questions-about-filter-and-broadcast/88520/1 "2022-10-10T12:47:31Z")

</div>

```julia
df = DataFrame(x=[3, 1, 2, 1], y=["b", "c", "a", "b"])
4×2 DataFrame
 Row │ x y
     │ Int64 String
─────┼───────────────
   1 │ 3 b
   2 │ 1 c
   3 │ 2 a
   4 │ 1 b

julia> filter(row->row.x==2,df)
1×2 DataFrame
 Row │ x y
     │ Int64 String
─────┼───────────────
   1 │ 2 a

```

But now I want to filter row.x=2 or 3,so i think of broadcast.and tried

```julia
a=[2,3]
julia> filter(row->row.x==a,df)
0×2 DataFrame
julia> filter.(row->row.x==a,df)
ERROR: MethodError: no method matching filter(::var"#31#32", ::Int64)
Closest candidates are:

```

I don’t know how to do.

---

<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:** [October 10, 2022, 12:54pm UTC](https://discourse.julialang.org/t/questions-about-filter-and-broadcast/88520/2 "2022-10-10T12:54:53Z")

</div>

For DataFrames you can pass a `Pair` as the first argument with a column name and a function to apply rowwise to that column.

Your main issue though has nothing to do with DataFrames but with the simple fact that

```julia
julia> 2 == [2, 3]
false

```

You are looking for containment, i.e. `in`:

```julia
julia> filter(:x => in([2, 3]), df)
2×2 DataFrame
 Row │ x y
     │ Int64 String
─────┼───────────────
   1 │ 3 b
   2 │ 2 a

```

P.S. to make what you tried originally work more directly you could have checked whether the value was equal to 2 or to 3:

```julia
julia> filter(:x => row -> row==2||row==3, df)
2×2 DataFrame
 Row │ x y
     │ Int64 String
─────┼───────────────
   1 │ 3 b
   2 │ 2 a

```

But that’s a bit cumbersome especially for larger collections.
