# How to get the index of the rows with non-NaN values for multiple vectors?

**URL:** <https://discourse.julialang.org/t/how-to-get-the-index-of-the-rows-with-non-nan-values-for-multiple-vectors/73315>\
**Category:** General Usage\
**Tags:** question, indexing, arrays\
**Created:** [December 19, 2021, 2:51am UTC](https://discourse.julialang.org/t/how-to-get-the-index-of-the-rows-with-non-nan-values-for-multiple-vectors/73315 "2021-12-19T02:51:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [December 19, 2021, 2:51am UTC](https://discourse.julialang.org/t/how-to-get-the-index-of-the-rows-with-non-nan-values-for-multiple-vectors/73315/1 "2021-12-19T02:51:24Z")

</div>

I have 4 vectors of data: A, B, C, D. My goal is to get the index of the rows where all 4 values being non-NaN.

Here is my code:  
`Ind1 = intersect.(.!isnan.(A), .!isnan.(B), .!isnan.(C), .!isnan.(D));`

Why doesn’t it work? The results are like the below:  
` Vector{Bool}[[0], [0], [0], [0], [0], [0], [0], [0], [0], [0]]`;

What is the correct way to do this? Many thanks!

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [December 19, 2021, 3:02am UTC](https://discourse.julialang.org/t/how-to-get-the-index-of-the-rows-with-non-nan-values-for-multiple-vectors/73315/2 "2021-12-19T03:02:36Z")

</div>

Your intersection does actually have the information you want, but it’s slightly weird as you are intersecting several _numbers_, `Bool`, and numbers are iterable with one element.

There are many other ways, perhaps some easier to read than others:

```julia
julia> A, B, C = (rand([1,2,NaN],10) for _ in 1:3);

julia> map(A,B,C) do a,b,c
        !(isnan(a) | isnan(b) | isnan(c))
       end |> findall
3-element Vector{Int64}:
  1
  3
 10

julia> findall(@. !(isnan(A) | isnan(B) | isnan(C)))
3-element Vector{Int64}:
  1
  3
 10

julia> findall(@. !any(isnan, tuple(A,B,C)))
3-element Vector{Int64}:
  1
  3
 10

julia> all(!isnan, hcat(A,B,C); dims=2) |> vec |> findall
3-element Vector{Int64}:
  1
  3
 10

julia> intersect.(.!isnan.(A), .!isnan.(B), .!isnan.(C))
10-element Vector{Vector{Bool}}:
 [1]
 []
 [1]
 []
 []
 []
 []
 [0]
 []
 [1]

julia> intersect(true, true, false)
Bool[]

julia> intersect(true, true, true)
1-element Vector{Bool}:
 1

julia> intersect(false, false, false)
1-element Vector{Bool}:
 0

```

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [December 19, 2021, 3:10am UTC](https://discourse.julialang.org/t/how-to-get-the-index-of-the-rows-with-non-nan-values-for-multiple-vectors/73315/3 "2021-12-19T03:10:44Z")

</div>

Many thanks for the multiple solutions. They work well 👍

> [@mcabbott](#):
>
> `all(!isnan, hcat(A,B,C); dims=2)`
