# Adding rows to data frame

**URL:** <https://discourse.julialang.org/t/adding-rows-to-data-frame/131925>\
**Category:** General Usage\
**Tags:** dataframes\
**Created:** [August 28, 2025, 11:55pm UTC](https://discourse.julialang.org/t/adding-rows-to-data-frame/131925 "2025-08-28T23:55:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SergeantMike](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sergeantmike/32/202613_2.png) [@SergeantMike](https://discourse.julialang.org/u/SergeantMike)\
**Post date:** [August 28, 2025, 11:55pm UTC](https://discourse.julialang.org/t/adding-rows-to-data-frame/131925/1 "2025-08-28T23:55:35Z")

</div>

I have a dataset that looks like this:

| Elapsed Days | Insects Collected on that day |
| --- | --- |
| 1 | 0 |
| 2 | 3 |
| 4 | 25 |
| 5 | 21 |
| 6 | 14 |
| 8 | 2 |

and I have a second dataset that is similar but is missing different days

| Elapsed Days | Insects Collected on that day |
| --- | --- |
| 1 | 1 |
| 3 | 4 |
| 4 | 17 |
| 5 | 43 |
| 8 | 2 |
| 12 | 3 |

I want to fill in the missing day in the sequence and place a zero in insects collected column

I could do this manually, but I have 34 datasets some with only 4 data points and some with 18 data points. I want all of the datasets to have the same number of rows. I know I could do it with and “if” or “for/end” loop but that seems like the brute force method and was hoping Julia had a more elegant way to do this

Thank you  
Mike

---

<div class="post-metadata">

**Author:** ![technocrat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/technocrat/32/220947_2.png) [@technocrat](https://discourse.julialang.org/u/technocrat)\
**Post date:** [August 29, 2025, 1:02am UTC](https://discourse.julialang.org/t/adding-rows-to-data-frame/131925/2 "2025-08-29T01:02:04Z")

</div>

```julia-auto

master = DataFrame(elapsed = 1:18)
master.collected .= 0

set_1 = DataFrame(elapsed = [1,2,4,5,6,8], collected = [0,3,25,21,14,2])
set_2 = DataFrame(elapsed = [1,3,4,5,8,12], collected = [1,4,17,43,2,3])

master = leftjoin(master, set_1, on=:elapsed, makeunique=true)
master = leftjoin(master, set_2, on=:elapsed, makeunique=true)
master.collected_1 = coalesce.(master.collected_1, 0)
master.collected_2 = coalesce.(master.collected_2, 0)
master.collected = master.collected_1 .+ master.collected_2
sort!(master, :elapsed)
println(master)
18×4 DataFrame
 Row │ elapsed collected collected_1 collected_2 
     │ Int64 Int64 Int64 Int64       
─────┼──────────────────────────────────────────────
   1 │ 1 1 0 1
   2 │ 2 3 3 0
   3 │ 3 4 0 4
   4 │ 4 42 25 17
   5 │ 5 64 21 43
   6 │ 6 14 14 0
   7 │ 7 0 0 0
   8 │ 8 4 2 2
   9 │ 9 0 0 0
  10 │ 10 0 0 0
  11 │ 11 0 0 0
  12 │ 12 3 0 3
  13 │ 13 0 0 0
  14 │ 14 0 0 0
  15 │ 15 0 0 0
  16 │ 16 0 0 0
  17 │ 17 0 0 0
  18 │ 18 0 0 0

```

---

<div class="post-metadata">

**Author:** ![SergeantMike67](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sergeantmike67/32/25103_2.png) [@SergeantMike67](https://discourse.julialang.org/u/SergeantMike67)\
**Post date:** [August 29, 2025, 1:37am UTC](https://discourse.julialang.org/t/adding-rows-to-data-frame/131925/3 "2025-08-29T01:37:47Z")

</div>

Thank you so much. I never thought about LeftJoin. Makes perfect sense now.
