title: Randomly extract a series of consecutive numbers from a sequence
body: <p>Using R, I am currently trying to randomly extract (different starting points) a series of 5 consecutive integers. I tried the function provided in the answer here - <a href="https://stackoverflow.com/questions/32945338/randomly-extract-a-number-of-consecutive-items-from-a-sequence-in-r">Randomly extract a number of consecutive items from a sequence in R</a>, but I keep running into this error</p>
  <pre><code># function used to subset a randomly chosen set of 5 integers
  extractRandWindow &lt;- function(x, p){
    firstIndex = sample(seq(length(x) - p + 1), 1)
    x[firstIndex:(firstIndex + p -1)]
  }
  
  # below files corresponds to a vector containing a series of integers
  
  subset &lt;- extractRandWindow(files,5)
  
  # I keep getting this error below
  
  Error in x[firstIndex:(firstIndex + p - 1)] : 
    only 0's may be mixed with negative subscripts
  </code></pre>
  <p>Based on @Gregor Thomas' suggestion, here's the class and structure of the strings:</p>
  <pre><code>&gt; dput(files)
  c(&quot;D:\\2020-summer\\HP36P1B\\HP36P1B_20200304_160000.WAV&quot;, &quot;D:\\2020-summer\\HP36P1B\\HP36P1B_20200304_160500.WAV&quot;, 
  &quot;D:\\2020-summer\\HP36P1B\\HP36P1B_20200304_161000.WAV&quot;, &quot;D:\\2020-summer\\HP36P1B\\HP36P1B_20200304_161500.WAV&quot;)
  </code></pre>
  <p>Any solutions? I realized my dput has &lt;number of elements requested. That's the cause of the error.</p>