indexin
indexin(a, b)
Returns a vector containing the highest index in b
for each value in a
that is a member of b
. The output vector contains 0 wherever a
is not a member of b
.
Examples
julia> indexin([1, 2, 3], [3, 2, 1, 4])
3-element Array{Int64,1}:
3
2
1
julia> indexin(["apple", "banana", "orange"], ["orange", "apple", "grape"])
3-element Array{Int64,1}:
2
1
0
julia> indexin([true, false, true], [false, true])
3-element Array{Int64,1}:
2
1
0
Common mistake example:
julia> indexin([1, 2, 3], [])
3-element Array{Int64,1}:
0
0
0
In this example, the second argument b
is an empty array. As a result, all elements of a
are not members of b
, and the output vector contains only zeros. Make sure to provide a non-empty array for b
to get meaningful results from indexin
.
See Also
User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.