findin

findin(a, b)

Returns the indices of elements in collection a that appear in collection b

Examples

julia> findin([1,2,2],[2,4,5])
2-element Array{Int64,1}:
 2
 3
julia> findin([1,2,3],[2,4,5])
1-element Array{Int64,1}:
 2

julia> foo = [2, 5, 7, 5, 2, -1];
julia> bar = [2, 5, 4];
julia> findin(bar, foo)
1
2
julia> a = [10, 20, 30, 40, 50];
julia> b = [20, 40, 60];
julia> findin(a, b)
2-element Array{Int64,1}:
 2
 4

In this example, the function findin returns the indices of elements in the collection a that appear in the collection b. The elements 20 and 40 are present in both a and b, so their indices [2, 4] are returned.

julia> names = ["Alice", "Bob", "Charlie", "David"];
julia> search_names = ["Charlie", "Frank"];
julia> findin(names, search_names)
1-element Array{Int64,1}:
 3

Here, the function findin is used to find the indices of elements in the names array that appear in the search_names array. Only "Charlie" is present in both arrays, so its index 3 is returned.

Common mistake example:

julia> fruits = ["apple", "banana", "orange"];
julia> findin(fruits, "apple")
ArgumentError: `findin` requires the second argument to be an iterable collection, found String

In this example, the second argument to findin should be an iterable collection, but a single string was provided instead. Make sure to pass a collection as the second argument to avoid this error.

See Also

find, findfirst, findin, findlast, findmin, findn, findnext, findnz, findprev, rsearch, rsearchindex, searchsorted, searchsortedfirst, searchsortedlast, sort, sort!, sortcols, sortperm, sortperm!,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: