# Check if a combination of values exists across two rows

**URL:** <https://discourse.julialang.org/t/check-if-a-combination-of-values-exists-across-two-rows/43000>\
**Category:** New to Julia\
**Created:** [July 13, 2020, 7:40pm UTC](https://discourse.julialang.org/t/check-if-a-combination-of-values-exists-across-two-rows/43000 "2020-07-13T19:40:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)\
**Post date:** [July 13, 2020, 7:40pm UTC](https://discourse.julialang.org/t/check-if-a-combination-of-values-exists-across-two-rows/43000/1 "2020-07-13T19:40:16Z")

</div>

How can I check if a vector, say A, contains a particular value, and another vector, say B, contains another particular value - in the same row as the value was found in vector A? For example:

Target value in A is 9  
Target value in B is 7

A = [1;2;3;9]  
B = [8;1;2;7]

How can I check that the combination 9 and 7 exists?

---

<div class="post-metadata">

**Author:** ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)\
**Post date:** [July 13, 2020, 7:56pm UTC](https://discourse.julialang.org/t/check-if-a-combination-of-values-exists-across-two-rows/43000/2 "2020-07-13T19:56:34Z")

</div>

How about

```julia
C = reduce(&, hcat(A, B) .== [9 7], dims=2)
4×1 BitArray{2}:
 0
 0
 0
 1

```

If you want the index, you can use

```julia
findall(C)
1-element Array{CartesianIndex{2},1}:
 CartesianIndex(4, 1)

```

---

<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:** [July 13, 2020, 8:18pm UTC](https://discourse.julialang.org/t/check-if-a-combination-of-values-exists-across-two-rows/43000/3 "2020-07-13T20:18:11Z")

</div>

`zip` is probably good for this

```julia
julia> x = [1, 2, 3]
3-element Array{Int64,1}:
 1
 2
 3

julia> y = [4, 5, 6]
3-element Array{Int64,1}:
 4
 5
 6

julia> (3, 6) in zip(x, y)
true

```

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [July 13, 2020, 8:23pm UTC](https://discourse.julialang.org/t/check-if-a-combination-of-values-exists-across-two-rows/43000/4 "2020-07-13T20:23:10Z")

</div>

also, use `,` instead of `;`
