0

I have a column called signal with values stored for every minute of recording. I want to compare the first value with the second and if the difference is over 4, then it should output a 1, if under 4, then a 0. I then want to do this between the second and third, third and fourth, fourth and fifth, and so on.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user3021648
  • 67
  • 2
  • 3
  • 11
  • 1
    Try `diff(signal)>4`. – Roland Jan 16 '14 at 14:41
  • [Check this for information on how to provide a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Jaap Jan 16 '14 at 19:53

1 Answers1

0

You might try this:

df$newcolumn <- ifelse(diff(df$signal)>4, 1, 0)
Jaap
  • 81,064
  • 34
  • 182
  • 193