title: Filling missing values from other rows in group (including duplicates)
body: <p>I have a dataset which has some missing values which I want to fill with other members of the same group. However, in some cases there is more than one value for each group and in these cases I want all the rows in each group to be replicated to have one row containing each value.</p>
  
  <p>Sample data:</p>
  
  <pre><code>   ID group value
  1   1     A  blue
  2   2     A  &lt;NA&gt;
  3   3     A  &lt;NA&gt;
  4   4     B green
  5   4     B   red
  6   5     B  &lt;NA&gt;
  7   6     B  &lt;NA&gt;
  8   7     C  blue
  9   8     C green
  10  9     C    NA
  </code></pre>
  
  <p>What I want to end up with is:</p>
  
  <pre><code>  ID group value
  1  1     A  blue
  2  2     A  blue
  3  3     A  blue
  4  4     B green
  5  4     B   red
  6  5     B green
  7  5     B   red
  8  6     B green
  9  6     B   red
  10 7     C  blue
  11 7     C green
  12 8     C  blue
  13 8     C green
  14 9     C  blue
  15 9     C green
  </code></pre>
  
  <p>I have some cases where the group contains one ID which has two values (like group B) and others were there is more than one ID in the group, each with a different value (like C). In any case, I want a table where each member of the group has every value present in that group. I've found some answers dealing with simple cases like group A but none that have more than one value per group.</p>
  
  <p>==== EDIT ====</p>
  
  <p>My actual dataset is much bigger which has caused some additional problems. An updated sample table is below:</p>
  
  <pre><code>ID group value specific_value dataversion
  1     A  blue       sky_blue    version1
  2     A  &lt;NA&gt;           &lt;NA&gt;    version2
  3     A  &lt;NA&gt;           &lt;NA&gt;    version1
  4     B green   forest_green    version1
  4     B   red        scarlet    version1
  5     B  &lt;NA&gt;           &lt;NA&gt;    version2
  6     B  &lt;NA&gt;           &lt;NA&gt;        &lt;NA&gt;
  7     C  blue     royal_blue    version2
  8     C green     lime_green    version1
  9     C  &lt;NA&gt;           &lt;NA&gt;    version1
  </code></pre>
  
  <p>For each group I want to have a row with each set of value + specific_value from that group (but I wouldn't want a row with eg. blue and lime_green) for each member of the group. I want all the values for the other columns (ID, group, and dataversion) to be left as-is (including if eg. dataversion is NA).</p>
  
  <p>Expected output:</p>
  
  <pre><code>ID group value specific_value dataversion
  1     A  blue       sky_blue    version1
  2     A  blue       sky_blue    version2
  3     A  blue       sky_blue    version1
  4     B green   forest_green    version1
  4     B   red        scarlet    version1
  5     B green   forest_green    version2
  5     B   red        scarlet    version2
  6     B green   forest_green        &lt;NA&gt;
  6     B   red        scarlet        &lt;NA&gt;
  7     C  blue     royal_blue    version2
  7     C green     lime_green    version2
  8     C  blue     royal_blue    version1
  8     C green     lime_green    version1
  9     C  blue     royal_blue    version1
  9     C green     lime_green    version1
  </code></pre>
  
  <p>Ie. each combination of ID, group, and dataversion in the table is the same as the original table but there is now a row for each combination of value and specific_value for each group. Note in my actual table I have ~50 columns of data (1 grouping column, ~6 are the equivalent to value/specific value here and the rest are treated like ID/dataversion) so I'd prefer not to have to type every column name.</p>