2

Is there a function in base R, or a more elegant way to detect the step size in a vector increases?

At the moment I am using a combination of diff and unique.

xx <- seq(from = 0, to = 100, by = 5)

unique(diff(xx))
# 5
guyabel
  • 8,014
  • 6
  • 57
  • 86
  • 2
    Looks good to me. What's the problem with that approach? If the step size is always the same you could do just `x[2] - x[1]` or `diff(xx)[1]`. Either way, even there is some such special function, your approach looks perfectly fine to me. – David Arenburg May 06 '16 at 09:57
  • just wondering if there is something out there that I have missed – guyabel May 06 '16 at 10:00
  • `rle` also useful when the vector involves different step sizes – guyabel Nov 03 '16 at 07:31

0 Answers0