title: How to complete missing factor levels in data frame?
body: <p>Lets pretend I have something like this:</p>
  <pre><code>df &lt;- data.frame(
        PERSON = c(&quot;Peter&quot;, &quot;Peter&quot;, &quot;Marcel&quot; , &quot;Lisa&quot;, &quot;Lisa&quot;),        
        FRUIT = c(&quot;Apple&quot;, &quot;Peach&quot;,&quot;Apple&quot;, &quot;Apple&quot;, &quot;Peach&quot; ), 
        A = c(100, 200, 100, 200, 300), 
        B=c(1,2,3,4,5) )
  df$PERSON &lt;- as.factor(df$Person)
  df$FRUIT &lt;- factor(df$FRUIT, levels = c(&quot;Apple&quot;, &quot;Peach&quot;, &quot;Coconut&quot;))
  </code></pre>
  <p>Which resulsts in</p>
  <pre><code>str(df): 'data.frame':  5 obs. of  4 variables:
  $ PERSON: Factor w/ 3 levels &quot;Lisa&quot;,&quot;Marcel&quot;,..: 3 3 2 1 1
  $ FRUIT : Factor w/ 3 levels &quot;Apple&quot;,&quot;Peach&quot;,..: 1 2 1 1 2
  $ A     : num  100 200 100 200 300
  $ B     : num  1 2 3 4 5
  </code></pre>
  <p>I want to expand this data, frame so that for every PERSON there are all levels of FRUIT present, like this:</p>
  <pre><code> Person FRUIT   A B
  1  Peter Apple 100 1
  2  Peter Peach 200 2
  3  Peter Coconut 0 0
  4 Marcel Apple 100 3
  5 Marcel Peach 0 0
  6 Marcel Coconut 0 0
  7   Lisa Apple 200 4
  8   Lisa Peach 300 5
  9   Lisa Coconut 0 0
  </code></pre>
  <p>Missing values for <code>A</code> and <code>B</code> should be filled with 0.</p>
  <p>I tried <code>tidyr::complete(df$FRUIT, 0)</code>, but it seems, that I used this function wrong.</p>