# How would I use the any function to find unique members of any arbitrary amount of dataframes?

**URL:** <https://discourse.julialang.org/t/how-would-i-use-the-any-function-to-find-unique-members-of-any-arbitrary-amount-of-dataframes/44213>\
**Category:** General Usage\
**Created:** [August 3, 2020, 7:59pm UTC](https://discourse.julialang.org/t/how-would-i-use-the-any-function-to-find-unique-members-of-any-arbitrary-amount-of-dataframes/44213 "2020-08-03T19:59:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julia1](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Julia1](https://discourse.julialang.org/u/Julia1)\
**Post date:** [August 3, 2020, 7:59pm UTC](https://discourse.julialang.org/t/how-would-i-use-the-any-function-to-find-unique-members-of-any-arbitrary-amount-of-dataframes/44213/1 "2020-08-03T19:59:23Z")

</div>

Hi how’s it going,

I’m looking to write something where I don’t have to hard code how many groups I’m searching through, and find the unique members of each group. For example:

```julia
group1 = DataFrame(:member=>["phil","bob","larry","dustin"])
group2 = DataFrame(:member=>["phil","bob",",mike","george"])
group3 = DataFrame(:member=>["larry","kevin",",phil","george"])

```

Now obviously here I could do a for loop and say something like

```julia
for val in unique(group1[!,:member])
    if !(val in group2[!,:member]) && !(val in group3[!,:member])
        print(val)
    end
end

```

but how would I do this if I didn’t know how many groups there were, and just wanted to return the unique members of each group that aren’t in any others.

Thanks

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [August 3, 2020, 8:11pm UTC](https://discourse.julialang.org/t/how-would-i-use-the-any-function-to-find-unique-members-of-any-arbitrary-amount-of-dataframes/44213/2 "2020-08-03T20:11:37Z")

</div>

How about this?

```julia
julia> group1 = DataFrame(:member=>["phil","bob","larry","dustin"]);

julia> group2 = DataFrame(:member=>["phil","bob",",mike","george"]);

julia> group3 = DataFrame(:member=>["larry","kevin",",phil","george"]);

julia> dfs = [group1, group2, group3];

julia> uniques = Dict();

julia> for i in 1:length(dfs)
           this_one = dfs[i].member
           other_ones = reduce(vcat, map(t -> t.member, dfs[setdiff(1:length(dfs), i)])) 
           uniques[i] = setdiff(this_one, other_ones)
       end

julia> uniques
Dict{Any,Any} with 3 entries:
  2 => [",mike"]
  3 => ["kevin", ",phil"]
  1 => ["dustin"]

```

---

<div class="post-metadata">

**Author:** ![Julia1](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Julia1](https://discourse.julialang.org/u/Julia1)\
**Post date:** [August 4, 2020, 12:19pm UTC](https://discourse.julialang.org/t/how-would-i-use-the-any-function-to-find-unique-members-of-any-arbitrary-amount-of-dataframes/44213/3 "2020-08-04T12:19:31Z")

</div>

thanks man!

---

<div class="post-metadata">

**Author:** ![Julia1](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Julia1](https://discourse.julialang.org/u/Julia1)\
**Post date:** [August 6, 2020, 5:05pm UTC](https://discourse.julialang.org/t/how-would-i-use-the-any-function-to-find-unique-members-of-any-arbitrary-amount-of-dataframes/44213/4 "2020-08-06T17:05:21Z")

</div>

What if I wanted to make it a threshold, so that instead of an absolute set difference, I say, “if any value shows up in greater than 75% of the groups, then it’s non unique, other than that it’s unique.”

So in this case, larry and bob would be considered unique since they show up in 2/3 of the groups , below the 75% threshold

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [August 7, 2020, 12:59pm UTC](https://discourse.julialang.org/t/how-would-i-use-the-any-function-to-find-unique-members-of-any-arbitrary-amount-of-dataframes/44213/5 "2020-08-07T12:59:36Z")

</div>

remember that `mean` can take in a function, so you would do something like

```julia
function amount(name, dfs) # dfs is dfs[Not(group1)] for example
    mean(t -> name in t.member, dfs)
end

```
