What is julia lang equivalent to R's %in%?

Hello, I have a vector:

b = ["NC_001422", "NZ_CP008698", "NZ_CP016318" , "NZ_CP010905", "NZ_CP019649",
         "NZ_CP029707" , "NZ_CP011102", "NC_006905", "NC_006905", 
         "NC_009142", "NC_006322", "NC_013971", "NC_017451", "NC_014494",
         "NC_017340", "NC_008024", "NC_011375", "NC_007296", "NC_008022",
         "NC_004070", "NC_003197", "NC_012225", "NC_011566", "NC_012751",
         "NC_005362", "NC_002976", "NC_026268", "NC_002737"]

I would like to test if the object “AC_000006” is present in vector b. What would be Julia’s equivalent to R’s %in%?
Thank you

julia> "NC_011566" ∈ b
true

You have to type \in + tab to get ∈. Otherwise you can use "NC_011566" in b or in("NC_011566", b) (they are all the same thing).

3 Likes

Thanks

No need to reach for unicode in this particular case:

julia> "NC_011566" in b
true

As with all operators, though, you can also just call it as a normal function:

julia> in("NC_011566", b)
true

Unlike R, there’s not a general mechanism for putting an arbitrary function in infix position, and this is the only “word” that works like this. All other infix operations are symbols of some sort — which you can define and use yourself.

2 Likes
jl> 3 isa Int
true

:wink:

This is not a generic function, though.

1 Like

Ah, thanks. I knew as I was writing that sentence that I was likely to be wrong. If I were feeling snarky I’d say that “isa” isn’t a (dictionary) word! :stuck_out_tongue:

You could resurrect GitHub - Ismael-VC/InfixFunctions.jl: Julia infix function hack.

3 Likes

But where certainly is :wink:

2 Likes