title: Conditionally create new column in R
body: <p>I would like to create a new column in my dataframe that assigns a categorical value based on a condition to the other observations. 
  In detail, I have a column that contains timestamps for all observations. The columns are ordered ascending according to the timestamp. 
  Now, I'd like to calculate the difference between each consecutive timestamp and if it exceeds a certain threshold the factor should be increased by 1 (see Desired Output).</p>
  
  <p><a href="https://i.stack.imgur.com/wB23t.png" rel="nofollow noreferrer">Desired Output</a></p>
  
  <p>I tried solved it with a for loop, however that takes a lot of time because the dataset is huge.
  After searching for a bit I found this approach and tried to adapt it: <a href="https://stackoverflow.com/questions/33505541/r-how-can-i-check-if-a-value-in-a-row-is-different-from-the-value-in-the-previ">R - How can I check if a value in a row is different from the value in the previous row?</a></p>
  
  <pre><code>ind &lt;- with(df, c(TRUE, timestamp[-1L] &gt; (timestamp[-length(timestamp)]-7200)))
  </code></pre>
  
  <p>However, I can not make it work for my dataset.<br>
  Thanks for your help!</p>