title: Compare value in a column within groups in dplyr
body: <p>I would like to compare the values inside a grouped data.frame using dplyr, and create a dummy variable, or something similar, indicating which is bigger. Couldn't figure it out!</p>
  
  <p>Here is some reproducible code:</p>
  
  <pre><code>table &lt;- structure(list(species = structure(c(1L, 1L, 1L, 2L, 2L, 2L), .Label = c("Adelophryne adiastola", 
  "Adelophryne gutturosa"), class = "factor"), scenario = structure(c(3L, 
  1L, 2L, 3L, 1L, 2L), .Label = c("future1", "future2", "present"
  ), class = "factor"), amount = c(5L, 3L, 2L, 50L, 60L, 40L)), .Names = c("species", 
  "scenario", "amount"), class = "data.frame", row.names = c(NA, 
  -6L))
  &gt; table
                  species scenario amount
  1 Adelophryne adiastola  present      5
  2 Adelophryne adiastola  future1      3
  3 Adelophryne adiastola  future2      2
  4 Adelophryne gutturosa  present     50
  5 Adelophryne gutturosa  future1     60
  6 Adelophryne gutturosa  future2     40
  </code></pre>
  
  <p>I would group the df by <code>species</code>.
  I want to create a new column, can be <code>increase_amount</code>, where the amount in every "future" is compared to the "present". I could get 1 when the value has increased and 0 when it has decreased.</p>
  
  <p>I have been trying with a for loop that goes throw each of the species, but the df contains over 50,000 of them and it takes too long for the times I will have to re-do the operation...</p>
  
  <p>Someone know a way?
  Thanks a lot!</p>