I often want to loop over a long array or column of a dataframe, and for each item, see if it is a member of another array. Rather than doing
giant_list =
The indexin function does something similar to what you want:
indexin(a, b)Returns a vector containing the highest index in
bfor each value inathat is a member ofb. The output vector contains 0 whereverais not a member ofb.
Since you want a boolean for each element in your giant_list (instead of the index in good_letters), you can simply do:
julia> indexin(giant_list, good_letters) .> 0
3-element BitArray{1}:
true
false
false
The implementation of indexin is very straightforward, and points the way to how you might optimize this if you don't care about the indices in b:
function vectorin(a, b)
bset = Set(b)
[i in bset for i in a]
end
Only a limited set of names may be used as infix operators, so it's not possible to use it as an infix operator.