title: Find Difference Between Two Rows Using dplyr: suppresswarnings() leads to NA forced by Coercion
body: <p>I want to find the difference between rows based on specific criteria. I managed to do this using dplyr and the mutate function with lag. I have about 10 columns and 500 rows. I am able to find the difference for most rows in columns except for a couple.  The problem is that the two of the columns are in factors form and using my code leads to the warning message: in ops.factor not meaningful for factors. To combat this, I tried changing numeric to character. </p>
  
  <pre><code>y &lt;- mutate(df, d_f = df$L - lag(df$L) + n())    
  
  x &lt;- as.numeric(as.character(df$z))
  </code></pre>
  
  <p>This leads to a warning message. Using suppresswarnings(x) leads to all values in the column to become NA by coercion. </p>
  
  <p>How can I change the factors to a different form so that I can find the difference between the rows? The columns causing this problem are in percentages if that makes any difference. </p>
  
  <p>On a side note: I'm new to R and it does seem pretty cool. </p>