R: How to find non-sequential elements in an array -
I have an array of numbers in it and I do not already know what the number will be. I want to separate which are not sequential to the previous number (except for the first number in the sequence).
For example: array: 2 3 4 5 10 11 12 15 18 19 20 23 24
I would like to return -text "itemprop =" text "> Try If you want to get the final sequential number, try 2 10 15 < / P>
v1 & lt; -c (2: 5,10: 12,15, 18:20, 23:24) v1 [c (TRUE, diff (v1) = 1 )] # [1] 2 10 15 18 23
update
< Code> v1 [c (diff (v1)! = 1, TRUE)] # [1] 5 12 15 20 24
Comments
Post a Comment