title: Finding patterns of values within a table in R
body: <p>My data is a time series with columns of Date, and a Value sequence between 1 and 4. I'm trying to find patterns of consecutive values that run from 1-3 or 4-2 and retrieve the date on which the pattern is completed (ie. when 3 is hit in the first scenario, and 2 in the second). </p>
  
  <p>The input data is as follows:</p>
  
  <pre><code>data.frame(Date=seq(as.Date("2010/1/1"), as.Date("2010/1/20"), "day"),
  Value=c(1,2,3,4,3,4,3,4,3,2,1,2,1,2,3,4,3,4,3,2))
  
  
     Date         Value
  1  2010-01-01     1
  2  2010-01-02     2
  3  2010-01-03     3
  4  2010-01-04     4
  5  2010-01-05     3
  6  2010-01-06     4
  7  2010-01-07     3
  8  2010-01-08     4
  9  2010-01-09     3
  10 2010-01-10     2
  ...
  </code></pre>
  
  <p>The output I desire is, for example:</p>
  
  <pre><code>data.frame(Date=as.Date(c("2010/1/3","2010/1/10","2010/1/15","2010/1/20")),
  Value=c("Win","Loss","Win","Loss"))
  
  Date       Value
  2010-01-03   Win
  2010-01-10  Loss
  2010-01-15   Win
  2010-01-20  Loss
  </code></pre>
  
  <p>Where the former sequence (Win) can be distinguished from the latter (loss).</p>
  
  <p>Many thanks!</p>