# Subset differences between || and | operators

**URL:** <https://discourse.julialang.org/t/subset-differences-between-and-operators/118510>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [August 23, 2024, 12:26am UTC](https://discourse.julialang.org/t/subset-differences-between-and-operators/118510 "2024-08-23T00:26:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrian\_G](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adrian_g/32/202838_2.png) [@Adrian\_G](https://discourse.julialang.org/u/Adrian_G)\
**Post date:** [August 23, 2024, 12:26am UTC](https://discourse.julialang.org/t/subset-differences-between-and-operators/118510/1 "2024-08-23T00:26:51Z")

</div>

Hi, I’m new to Julia. I have some questions regarding the subset function of DataFrames. I would appreciate if you could help me to solve them.

```julia
df = DataFrame(x=[2,0,8,9], y=[0,0,0,8], z=["A", "B", "C", "D"], w=["A","A","B", "B"])

```

When I filter the dataframe using the || operator, I get an incorrect result. It does not filter correctly the :y column.

```julia
subset(df , [:x, :y] => ByRow((a,b)-> a !=0 || b !=0))

```

But when I use the | operator the filter is correct.

```julia
subset(df , [:x, :y] => ByRow((a,b)-> a !=0 | b !=0))

```

On the other hand, if I run the following code, I get an error because I am not using the || operator.

```julia
subset(df , [:z, :w] => ByRow((a,b)-> a =="A" | b == "A" ))
subset(df , [:z, :w] => ByRow((a,b)-> a =="A" || b == "A" ))

```

So my doubts are:

why in the first case the || operator gives an incorrect result when the variable is numeric. While in the second case, when the variable is a string, it gives a correct result.

I apologize if my English is not understood well.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 23, 2024, 1:06am UTC](https://discourse.julialang.org/t/subset-differences-between-and-operators/118510/2 "2024-08-23T01:06:29Z")

</div>

> [@Adrian\_G](#):
>
> `a !=0 | b !=0`

This doesn’t mean what you think: the `|` operator has lower precedence than `!=`, so your expression is equivalent to `a != (0 | b) != 0`.

And since `0 | b` is just `b` for any integer `b`, this means that what you have is effectively `a != b != 0`.

> [@Adrian\_G](#):
>
> When I filter the dataframe using the || operator, I get an incorrect result. It does not filter correctly the :y column.

What do you mean? I get:

```julia
julia> subset(df , [:x, :y] => ByRow((a,b)-> a !=0 || b !=0))
3×4 DataFrame
 Row │ x y z w      
     │ Int64 Int64 String String 
─────┼──────────────────────────────
   1 │ 2 0 A A
   2 │ 8 0 C B
   3 │ 9 8 D B

```

which looks correct to me.

It sounds like what you want is `a != 0 && b != 0`, not `||`?

---

<div class="post-metadata">

**Author:** ![Adrian\_G](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adrian_g/32/202838_2.png) [@Adrian\_G](https://discourse.julialang.org/u/Adrian_G)\
**Post date:** [August 23, 2024, 1:20am UTC](https://discourse.julialang.org/t/subset-differences-between-and-operators/118510/3 "2024-08-23T01:20:14Z")

</div>

Thank you for your response! You are right, I got confused.
