title: To find the difference between two column elements in a data frame
body: <p>My question is a very basic one and I am new to R and programming. I have a data frame <code>RESULT</code> with two columns <code>Max</code>, <code>Min</code> and 500 rows. I just want to find the difference between <code>Max</code> and <code>Min</code> and put the value in a third column <code>Difference</code>. I tried with the code:</p>
  
  <pre><code>select Max, Min, Max-Min as Difference from RESULT.
  </code></pre>
  
  <p>But I am getting </p>
  
  <blockquote>
    <p>Error: unexpected symbol in "select Max".</p>
  </blockquote>
  
  <p>I also tried just with:  </p>
  
  <pre><code>Difference&lt;-c(RESULT$Max-RESULT$Min) 
  </code></pre>
  
  <p>for which I am getting: </p>
  
  <blockquote>
    <p>Warning Message</p>
    
    <p>In Ops.factor(RESULT$Max, RESULT$Min) :
          - not meaningful for factors</p>
  </blockquote>
  
  <p>RESULT:</p>
  
  <pre><code>    Max Min
  1   NaN NaN
  2   25  NaN
  3   NaN NaN
  4   NaN NaN
  5   NaN NaN
  6   25.6   23.1
  </code></pre>
  
  <p>I want to display <code>NaN</code> or any other variable like <code>X</code> or <code>Y</code> in <code>Difference</code> column whenever there is <code>NaN</code> in Either of <code>Max</code> or <code>Min</code>.    The output should be like:</p>
  
  <pre><code>    Max Min   Difference
  1   NaN NaN   NaN
  2   25  NaN   NaN
  3   NaN NaN   NaN
  4   NaN 34    NaN
  5   NaN NaN   NaN
  6   25.6   23.1   2.5
  </code></pre>