# Occursin with a vector

**URL:** <https://discourse.julialang.org/t/occursin-with-a-vector/71769>\
**Category:** New to Julia\
**Created:** [November 19, 2021, 11:28am UTC](https://discourse.julialang.org/t/occursin-with-a-vector/71769 "2021-11-19T11:28:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jnewbie](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jnewbie](https://discourse.julialang.org/u/jnewbie)\
**Post date:** [November 19, 2021, 11:28am UTC](https://discourse.julialang.org/t/occursin-with-a-vector/71769/1 "2021-11-19T11:28:18Z")

</div>

Hi everyone,

> a = [“abc”, “def”,“ghi”]

I have an array a and a column of my dataframe df[:Column1].

Is it possible with the function “occursin” (or another one) to know if the elements of a are into df[:Column1] without making a loop “for i in a” ? Is there a way to broadcast occursin ?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [November 19, 2021, 11:36am UTC](https://discourse.julialang.org/t/occursin-with-a-vector/71769/2 "2021-11-19T11:36:31Z")

</div>

One way:

```julia
using DataFrames
df = DataFrame(Col1 = ["abc", "aaf","ghi", "bbc", "baf","bhi"])
a = ["abc", "ghi", "bhi"]
df.Col1 .∈ Ref(a)

```

---

<div class="post-metadata">

**Author:** ![jnewbie](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jnewbie](https://discourse.julialang.org/u/jnewbie)\
**Post date:** [November 19, 2021, 11:43am UTC](https://discourse.julialang.org/t/occursin-with-a-vector/71769/3 "2021-11-19T11:43:26Z")

</div>

Thanks !

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 30, 2023, 5:16pm UTC](https://discourse.julialang.org/t/occursin-with-a-vector/71769/4 "2023-07-30T17:16:19Z")

</div>

How to print those entries of `a ` that are contained in `df` ? What if instead of `df` we have to match with text in string ?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [July 30, 2023, 6:19pm UTC](https://discourse.julialang.org/t/occursin-with-a-vector/71769/5 "2023-07-30T18:19:49Z")

</div>

> [@raman\_kumar](#):
>
> How to print those entries of `a ` that are contained in `df` ?

Probably `filter` then.

```julia
filter(y -> y in df.x, a)

```

(This won’t be particularly fast, if that’s a problem)

There’s one of the functions of `findall` family that returns the index and the value of the elements, and could be used. But I don’t remember which one.

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [July 30, 2023, 6:25pm UTC](https://discourse.julialang.org/t/occursin-with-a-vector/71769/6 "2023-07-30T18:25:25Z")

</div>

for these needs the indexin() function comes in handy

```julia

julia> df[indexin(a,df.Col1),:Col1]
3-element Vector{String}:
 "abc"
 "ghi"
 "bhi"

```

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 31, 2023, 2:45am UTC](https://discourse.julialang.org/t/occursin-with-a-vector/71769/7 "2023-07-31T02:45:24Z")

</div>

> [@raman\_kumar](#):
>
> What if instead of `df` we have to match with text in string ?

@rocco_sprmnt21

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [July 31, 2023, 6:53am UTC](https://discourse.julialang.org/t/occursin-with-a-vector/71769/8 "2023-07-31T06:53:05Z")

</div>

do you mean like this?

```julia
str=join(["abc", "aaf","ghi", "bbc", "baf","bhi"])
a = ["abc", "ghi", "bhi"]

findall.(a,[str])

```
