title: Select data range from timestamp based on row.names
body: <p>If I have a data frame and I wish to select a training set based on time range  </p>
  
  <pre><code>df &lt;- data.frame(timestamp = seq(as.POSIXct('2013-08-02 12:00:00'),
                                  as.POSIXct('2013-08-06 05:00:00'), len =(45), 
                     x = sample(1:100, 45), y = sample(200:500, 45)))
  </code></pre>
  
  <p>I will now convert the timestamp into row.names</p>
  
  <pre><code>row.names(df) = df$timestamp
  </code></pre>
  
  <p>Since I have indexed the row.names I should be able to select a range for a training set: </p>
  
  <pre><code> # Select the range 
   s = '2013-08-02 12:00:00'
   e = '2013-08-03 10:15:00'
  
   # Select the training dataset 
  
   training = df[s:e,]
  </code></pre>
  
  <p>But when I run the above code I get the following error:</p>
  
  <pre><code> #Error in s:e : NA/NaN argument
   #In addition: Warning messages:
   #1: In `[.data.frame`(df, s:e, ) : NAs introduced by coercion
   #2: In `[.data.frame`(df, s:e, ) : NAs introduced by coercion
  </code></pre>
  
  <p>Can anyone please explain what I am doing wrong here!</p>
  
  <p>I know that ts or some other package will solve the issue, but isn't there any base R functions I can use. </p>
  
  <p>The answers I reviewed before posting my question. </p>
  
  <p><a href="https://stackoverflow.com/questions/31038050/select-rows-within-a-particular-time-range">Select rows within a particular time range</a></p>