# Joining two dataframes of different size only when colum values are coincident

**URL:** <https://discourse.julialang.org/t/joining-two-dataframes-of-different-size-only-when-colum-values-are-coincident/93855>\
**Category:** New to Julia\
**Tags:** dataframes\
**Created:** [February 1, 2023, 7:50am UTC](https://discourse.julialang.org/t/joining-two-dataframes-of-different-size-only-when-colum-values-are-coincident/93855 "2023-02-01T07:50:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Itzi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/itzi/32/46136_2.png) [@Itzi](https://discourse.julialang.org/u/Itzi)\
**Post date:** [February 1, 2023, 7:50am UTC](https://discourse.julialang.org/t/joining-two-dataframes-of-different-size-only-when-colum-values-are-coincident/93855/1 "2023-02-01T07:50:41Z")

</div>

Hi!

I would like to know what is the best method to join two DataFrames of different size but making one of the variables coincident. Here is an example:

> using DataFrames
> 
> df11 = DataFrame(time = 0:5:30, num = 1, value1 = rand(7), value2 = rand(7))
> 
> df12 = DataFrame(time = 0:5:30, num = 2, value1 = rand(7), value2 = rand(7))
> 
> df1 = vcat(df11,df12)
> 
> df2 = DataFrame(time = 10:5:25, num = 1, value3 = rand(4))

I would like to outerjoin or leftjoin `df1` and df2 with :time but only when in df1 num = 1

![image](https://global.discourse-cdn.com/julialang/original/3X/0/e/0e93086c57ecf4a29e7da9c6fb5da7646eed9c70.png)

now if I do it I can not join them because there are duplicate variable names. makeunique = true does not help to my objective and if i delete the row num the values are assigned to all values of time that coincide.

![image](https://global.discourse-cdn.com/julialang/original/3X/d/5/d56783b9e2e6c6f1b1be387a3147ade010c1f59a.png)

The idea would be that highlighted values show also missing

---

<div class="post-metadata">

**Author:** ![Rudi79](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rudi79/32/3884_2.png) [@Rudi79](https://discourse.julialang.org/u/Rudi79)\
**Post date:** [February 1, 2023, 12:59pm UTC](https://discourse.julialang.org/t/joining-two-dataframes-of-different-size-only-when-colum-values-are-coincident/93855/2 "2023-02-01T12:59:06Z")

</div>

Maybe I misunderstood what you want, but shouldn’t this do the trick?

```julia
ret = leftjoin(df1,df2, on = [:time, :num])

```

---

<div class="post-metadata">

**Author:** ![Itzi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/itzi/32/46136_2.png) [@Itzi](https://discourse.julialang.org/u/Itzi)\
**Post date:** [February 1, 2023, 1:18pm UTC](https://discourse.julialang.org/t/joining-two-dataframes-of-different-size-only-when-colum-values-are-coincident/93855/3 "2023-02-01T13:18:34Z")

</div>

Yes it does thank you!
