title: Compare and replace values among multiple columns using a vectorized code in R
body: <p>I can find many questions about conditionally replacing values of a (or multiple) column(s) based on a threshold value.</p>
  <p>However, what I want to solve is to replace the smaller (or larger) value with a specified value.
  For example, in the <code>swiss</code> dataset, I want to compare the last two columns (i.e. Catholic and Infant.Mortality) and replace the smaller value with 999 for each row.</p>
  <pre><code>&gt;   swiss[1:5, c(ncol(swiss), (ncol(swiss) - 1))]
               Infant.Mortality Catholic
  Courtelary               22.2     9.96
  Delemont                 22.2    84.84
  Franches-Mnt             20.2    93.40
  Moutier                  20.3    33.77
  Neuveville               20.6     5.16
  
  &lt;some code I want to write&gt;
  
  ### the expected result
               Infant.Mortality Catholic
  Courtelary               22.2     999
  Delemont                 999    84.84
  Franches-Mnt             999    93.40
  Moutier                  999    33.77
  Neuveville               20.6     999
  </code></pre>
  <p>I guess I can use <code>for</code> statement or other looping methods (e.g. row-wise <code>apply</code>) to do the comparison and replacement.<br />
  However, I will deal with a mega-size data (e.g. hundreds of millions of observations) so I want to find a way to do it rapidly (e.g. vectorized one).</p>
  <p>Thank you</p>