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 2 10 15 < / P>

-text "itemprop =" text ">

Try

  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

If you want to get the final sequential number, try

 < Code> v1 [c (diff (v1)! = 1, TRUE)] # [1] 5 12 15 20 24  


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -