title: How to convert only SOME positive numbers to negative numbers (conditional recoding)?
body: <p>I am looking for a convenient way to convert positive values (proportions) into negative values of the same variable, depending on the value of another variable.</p>
  
  <p>This is how the data structure looks like:</p>
  
  <pre><code>id Item Var1  Freq 
  1  P1   0    0.043
  2  P2   1    0.078
  3  P3   2    0.454
  4  P4   3    0.543
  5  T1   0    0.001
  6  T2   1    0
  7  T3   2    0.045
  8  T4   3    0.321
  9  A1   0    0.671
  ...
  </code></pre>
  
  <p>More precisely, I would like to put the numbers for Freq into the negative if Var1 &lt;= 1 (e.g. -0.043). </p>
  
  <p>This is what I tried:</p>
  
  <pre><code>for(i in 1: 180) {
  if (mydata$Var1 &lt;= "1") (mydata$Freq*(-1))}
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>mydata$Freq[mydata$Var1 &lt;= "1"] = -abs(mydata$Freq)}
  </code></pre>
  
  <p>In both cases, the negative sign is rightly set but the numbers are altered as well.</p>
  
  <p>Any help is highly appreciated. THANKS!</p>