Replacing missings based on values in two DataFrame columns

Given an input table like this:

 Row │ x      y      z       
     │ Int64  Int64  Int64?  
─────┼───────────────────────
   1 │   100      1  missing 
   2 │   101      1  missing 
   3 │   102      1  missing 
   4 │   103      1       10
   5 │   104      2  missing 
   6 │   105      2  missing 
   7 │   106      2       11
   8 │   107      2  missing 
   9 │   108      3       12
  10 │   109      3  missing 
  11 │   110      3  missing 
  12 │   111      3  missing 

What is the dataframian way of replacing all missings in :z by the single values also present, based on the grouping defined by :y?
Sought result:

12×3 DataFrame
 Row │ x      y      z       
     │ Int64  Int64  Int64  
─────┼───────────────────────
   1 │   100      1       10 
   2 │   101      1       10
   3 │   102      1       10 
   4 │   103      1       10
   5 │   104      2       11 
   6 │   105      2       11 
   7 │   106      2       11
   8 │   107      2       11 
   9 │   108      3       12
  10 │   109      3       12 
  11 │   110      3       12 
  12 │   111      3       12 

Herein some code to generate input data:

using DataFrames, Random
x = 100:111
y = repeat(1:3,inner=4)
z = vcat([shuffle([i,missing,missing,missing]) for i in 10:12]...)
df = DataFrame(x=x, y=y, z=z)

Thanks in advance.

This should do it

julia> using DataFramesMeta, Random;

julia> begin
           x=100:111
           y=repeat(1:3,inner=4)
           z=vcat([shuffle([i,missing,missing,missing]) for i in 10:12]...)
           df = DataFrame(x=x, y=y, z=z)
       end
12×3 DataFrame
 Row │ x      y      z
     │ Int64  Int64  Int64?
─────┼───────────────────────
   1 │   100      1  missing
   2 │   101      1  missing
   3 │   102      1  missing
   4 │   103      1       10
   5 │   104      2  missing
   6 │   105      2  missing
   7 │   106      2  missing
   8 │   107      2       11
   9 │   108      3       12
  10 │   109      3  missing
  11 │   110      3  missing
  12 │   111      3  missing

julia> @chain df begin
           groupby(:y)
           @transform :z = first(skipmissing(:z))
       end
12×3 DataFrame
 Row │ x      y      z
     │ Int64  Int64  Int64
─────┼─────────────────────
   1 │   100      1     10
   2 │   101      1     10
   3 │   102      1     10
   4 │   103      1     10
   5 │   104      2     11
   6 │   105      2     11
   7 │   106      2     11
   8 │   107      2     11
   9 │   108      3     12
  10 │   109      3     12
  11 │   110      3     12
  12 │   111      3     12

4 Likes