此堆栈link显示了如何为数组中的booleans
值返回missing
。
例如:
julia> A = [1, 2, 3, missing, 4, 5, 6, missing, 7, 8, missing, 9, 10]
13-element Array{Union{Missing, Int64},1}:
1
2
3
missing
4
5
6
missing
7
8
missing
9
10
julia> ismissing.(A)
13-element BitArray{1}:
false
false
false
true
false
false
false
true
false
false
true
false
false
您如何返回他们的索引?
答案 0 :(得分:1)
使用相同的示例,您可以这样做:
julia> A = [1, 2, 3, missing, 4, 5, 6, missing, 7, 8, missing, 9, 10]
13-element Array{Union{Missing, Int64},1}:
1
2
3
missing
4
5
6
missing
7
8
missing
9
10
# Below are the indices of the missing elements.
julia> findall(ismissing, A)
3-element Array{Int64,1}:
4
8
11
您还可以查找是否有任何或所有元素为missing
,以及第一个和最后一个索引:
julia> any(ismissing, A)
true
julia> all(ismissing, A)
false
julia> findfirst(ismissing, A)
4
julia> findlast(ismissing, A)
11