title: How to create a column that allocates designated values among rows sharing the same characteristics in R dataframe?
body: <p>My question is best expressed with the below example. Let's start with the below dataframe:</p>
  <pre><code>&gt; myData
    Name Group Code
  1    R     0    0
  2    R     0    2
  3    T     0    2
  4    R     0    0
  5    N     1    3
  6    N     1    0
  7    T     0    4
  
  myData &lt;- 
    data.frame(
      Name = c(&quot;R&quot;,&quot;R&quot;,&quot;T&quot;,&quot;R&quot;,&quot;N&quot;,&quot;N&quot;,&quot;T&quot;),
      Group = c(0,0,0,0,1,1,0),
      Code = c(0,2,2,0,3,0,4)
    )
  </code></pre>
  <p>Now, I'd like to add a column, <code>CodeGrp</code>, whereby if a row's <code>Group</code> is &gt; 0, then allocate the max <code>Code</code> for that <code>Group</code> to all <code>Group</code> members with the same <code>Group</code> number so the results look this (note that only one <code>Group</code> member (where <code>Group</code> &gt; 0) can have a <code>Code</code> &gt; 0 and the rest of those <code>Group</code> members have code 0; maybe there's something easier than my proposed max) can only be :</p>
  <pre><code>  Name Group Code CodeGrp Explain
  1    R     0    0       0 Copy over Code since Group = 0 
  2    R     0    2       2 Copy over Code since Group = 0
  3    T     0    2       2 Copy over Code since Group = 0
  4    R     0    0       0 Copy over Code since Group = 0
  5    N     1    3       3 Group is &gt; 0 so insert in CodeGrp column the max Code in this Group
  6    N     1    0       3 Group is &gt; 0 so insert in CodeGrp column the max Code in this Group
  7    T     0    4       4 Copy over Code since Group = 0
  </code></pre>
  <p>Any recommendations for how to do this, in a simple manner, using base R or dplyr?</p>