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,438
  • 68
  • 55
  • 126
user3021648
  • 67
  • 1
  • 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
  • 77,147
  • 31
  • 174
  • 185