title: Generate new column in dataframe, based on group-event
body: <p>I have a dataframe with three groups (x: 1, 2, 3) and some events (0 and 1 in y):</p>
  
  <pre><code>x &lt;- c(1, 1, 1, 2, 2, 3, 3, 3, 3)
  y &lt;- c(0, 0, 1, 0, 0, 0, 0, 0, 1)
  df &lt;- data.frame(x, y)
  df
  
  &gt; df
    x y
  1 1 0
  2 1 0
  3 1 1
  4 2 0
  5 2 0
  6 3 0
  7 3 0
  8 3 0
  9 3 1
  </code></pre>
  
  <p>Now i want to generate a new column z, based on the events in y: if there is any y = 1 in one group, the whole group should get a 1 for z; else NA. How can z be generated this way? df should look like:</p>
  
  <pre><code>&gt; df
    x y  z
  1 1 0  1
  2 1 0  1
  3 1 1  1
  4 2 0 NA
  5 2 0 NA
  6 3 0  1
  7 3 0  1
  8 3 0  1
  9 3 1  1
  </code></pre>
  
  <p>I am grateful for any help.</p>