title: Determine when a sequence of numbers has been broken in R
body: <p>Say I have a series of numbers:</p>
  
  <pre><code>seq1&lt;-c(1:20,25:40,48:60)
  </code></pre>
  
  <p>How can I return a vector that lists points in which the sequence was broken, like so: </p>
  
  <pre><code>   c(21,24)
      [1] 21 24
  
     c(41,47) 
      [1] 41 47
  </code></pre>
  
  <p>Thanks for any help. </p>
  
  <p>To show my miserably failing attempt: </p>
  
  <pre><code>nums&lt;-min(seq1):max(seq1) %in% seq1
  which(nums==F)[1]
  
  res.vec&lt;-vector()
  counter&lt;-0
  res.vec2&lt;-vector()
  counter2&lt;-0
  
  for (i in 2:length(seq1)){
    if(nums[i]==F &amp; nums[i-1]!=F){
      counter&lt;-counter+1
      res.vec[counter]&lt;-seq1[i]
    }
  
    if(nums[i]==T &amp; nums[i-1]!=T){
      counter2&lt;-counter2+1
      res.vec2[counter2]&lt;-seq1[i]
    }
  
  
  }
  
  cbind(res.vec,res.vec2)
  </code></pre>