title: Creating a new variable that flags every instance of a change in absolute value in R
body: <p>I'm working with processed data from motion sensors and would like some help manipulating the dataset. My variables include "Time" (in milliseconds) and "Shoulder Flexion" (in angles). I want to create a new variable that flags every time there is an absolute value change of 3 degrees in the "Shoulder Flexion" variable. Something like:</p>
  
  <pre><code>newdata &lt;- mydata %&gt;%
      mutate(changevariable = ifelse(Shoulder.Flexion = [absolute value change in 3 degrees], "1", "0")
  </code></pre>
  
  <p>, where each flag/"1" is in a sequence of ± 3 degrees.</p>
  
  <p>An example of my dataset:</p>
  
  <pre><code>structure(list(Time = c(0, 0.0078125, 0.015625, 0.023438, 0.03125, 
  0.039062, 0.046875, 0.054688, 0.0625, 0.070312, 0.078125, 0.085938, 
  0.09375, 0.10156, 0.10938, 0.11719, 0.125, 0.13281, 0.14062, 
  0.14844), Shoulder.Flexion = c(-9.4721, -12.098, -12.51, 12.253, 
  11.815, 11.385, 11.03, 10.766, 10.586, 10.472, 10.408, 10.381, 
  10.383, 10.407, 10.453, 10.521, 10.605, 10.695, 10.778, 10.846
  )), row.names = c(NA, 20L), class = "data.frame")
  </code></pre>
  
  <p>This point of this is to help me generate a value of the number of times a subject rotates 3 degrees in a specified time interval. Any help would be much appreciated.</p>
  
  <p>Thanks in advance.</p>