title: Replace row values with multiple conditions in r
body: <p>Currently Im working on a project and got stuck in one problem. I have to replace row values of a column with two conditions in different columns. Suppose:</p>
  
  <pre><code>x   y     m     n
  1  200P  Jan  Perm
  1  200T  Feb  Temp  
  1  300P  Jan  Perm
  2  200T  Feb  Temp      
  2  300T  Feb  Temp
  3  300P  Jan  Perm
  3  400P  Jan  Perm
  </code></pre>
  
  <p>I would like to change the values of column n based on x and y. </p>
  
  <pre><code>for each x
  check the value of y and n, if the first value of y with T is 
  Perm/Temp. Replace the rest of the values of unique x rows to that 
  value.
  </code></pre>
  
  <p>I tried but when I execute the code it replaces all Temp to Perm or Perm to Temp. But I want it to change just the values of the rows for that unique x. Can someone please help me with this. I want my output to be like:</p>
  
  <pre><code>x   y     m     n
  1  200P  Jan  Temp
  1  200T  Feb  Temp  
  1  300P  Jan  Temp
  2  200T  Feb  Temp      
  2  300T  Feb  Temp
  3  300P  Jan  Perm
  3  400P  Jan  Perm
  </code></pre>
  
  <p>I was trying to practice with another dataset with different conditions. For example:</p>
  
  <pre><code>a   b    c       d
  1   1   0.4    Minor
  1   1   0.4    Minor
  1   4   0.2    Minor
  1   2   2.4    Major
  2   4   0.2    Minor
  3   1   0.4    Minor
  3   4   0.2    Minor
  3   4   4.2    Major
  </code></pre>
  
  <p>I'm trying to replace 4 to 1 in column b with a condition that if it is 0.2 in column c. If 4 and 0.4 are in the same row, replace 4 to 1. </p>