title: Homogenize grouped values in R in panel dataset
body: <p>I have a household panel survey dataset. It has two surveys in it: one for individuals and one for households. One person in each household answers both while all other people in the household answer the individual survey only. The municipal location is only in the person who filled the houehold. The dataset is a panel so each observation is there multiple times for different waves of the study. So basically I have something like this:</p>
  
  <pre><code>  df &lt;- data.frame(id = c (11,11, 12,12,13, 13,14, 14,21, 21,22, 22,31, 31,32, 32,33, 33,34, 34,41, 41,42, 42,43, 43,44, 44,51, 51,61, 61,62, 62))
  df$idhousehold &lt;- c(1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4, 5,5, 6, 6, 6,6)
  df$municipality &lt;- c(NA, NA, NA,NA, NA, NA,"A","A",NA, NA, "A", "A",NA, NA,NA, NA, "B", "B", NA,NA, "A", "A",NA,NA,NA,NA,NA,NA, "C", "C","B","B",NA, NA)
  df$year &lt;- c(1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2)
  df
  </code></pre>
  
  <p>What I basically want to do is to assign the same municipality value for everyone within the same household. In the example above this means everyone in households 1, 2 and 4 has value "A" for municipality, for households 3 and 6 everyone has B and C in 5. I cannot manually do that because the dataset has around 130k observations. </p>
  
  <p>I tried multiple ways of goruping the data and mutating a new variable but I am not capable of getting what I want.</p>
  
  <p>Thanks for the help!</p>