title: Impute missing records based on week and year in r
body: <p>I want to impute missing weeks record with 0 values in duration column for each household, individual combination.</p>
  <p><a href="https://i.stack.imgur.com/2ECDc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2ECDc.png" alt="enter image description here" /></a></p>
  <p>The minimum week here is w51 of 2021 and goes upto w4 of 2022</p>
  <p>For Household 1001 - individual 1 combination, week 3 is missing in the sequence.</p>
  <p>Household 1002 - individual 2, week 52,week 2 and week 4 is missing</p>
  <p>Final dataset would be:</p>
  <p><a href="https://i.stack.imgur.com/eE9fN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eE9fN.png" alt="enter image description here" /></a></p>
  <p>what I tried is using complete function from tidyr after group by with household and individual but its not working.</p>
  <p>In actual dataset minimium and maximum weeks will be changing.</p>
  <p>Here is the sample dataset</p>
  <pre><code> data &lt;- data.frame(household=c(1001,1001,1001,1001,1001,1002,1002,1002,1003,1003,1003),
                 individual = c(1,1,1,1,1,2,2,2,1,1,1),
                 year = c(2021,2021,2022,2022,2022,2021,2022,2022,2022,2022,2022),
                 week =c(&quot;w51&quot;,&quot;w52&quot;,&quot;w1&quot;,&quot;w2&quot;,&quot;w4&quot;,&quot;w51&quot;,&quot;w1&quot;,&quot;w3&quot;,&quot;w1&quot;,&quot;w2&quot;,&quot;w3&quot;),
                 duration =c(20,23,24,56,78,12,34,67,87,89,90))
  </code></pre>