title: How to apply if condition in select columns in R
body: <p>I have a dataframe called <code>cc</code>. I want to apply if condition to change value above 50 as 50 and below zero as zero only in select columns(i.e only to column 3 and 4). I tried doing like this below but could not get what I need. </p>
  
  <p>cc</p>
  
  <pre><code> s.no       A        B       C       
      1         Inf     Inf      999.9
      2        -0.43    30       23
      3         34      -2       233   
  </code></pre>
  
  <p>mycode </p>
  
  <pre><code> if (cc[,3:4]&gt;50){
        cc[,3:4]&lt;-50
         }
  
  if (cc[,3:4]&lt;0){
        cc[,3:4]&lt;-0
         }
  </code></pre>
  
  <p>result I want:</p>
  
  <pre><code>        s.no       A        B       C       
          1         Inf     50       50
          2        -0.43    30       23
          3         34      0        50  
  </code></pre>