title: Conditionally returning a vector of some row values based on another column's row values
body: <p>Here is a reproducible data set:</p>
  
  <pre><code>set.seed(55);
  data &lt;- rnorm(12);
  dates &lt;- as.POSIXct("2019-03-18 10:30:00", tz = "CET") + 0:(length(data)-1)*60;
  
  R &lt;- xts(x = data, order.by = dates) %&gt;%
    sample(size = 10) %&gt;%
    fortify.zoo()
  
  colnames(R) &lt;- c("Time", "Rf");
  R$lab &lt;- "A"
  R$lab[c(5, length(R$lab))] &lt;- "BB"
  R$diff &lt;- c(NA, diff(R$Rf))
  </code></pre>
  
  <p>Output looks like:</p>
  
  <pre><code>&gt; R
                    Time           Rf lab       diff
  1  2019-03-18 10:30:00  0.120139084   A         NA
  2  2019-03-18 10:32:00  0.151582984   A  0.0314439
  3  2019-03-18 10:33:00 -1.119221005   A -1.2708040
  4  2019-03-18 10:34:00  0.001908206   A  1.1211292
  5  2019-03-18 10:36:00 -0.505343855  BB -0.5072521
  6  2019-03-18 10:37:00 -0.099234393   A  0.4061095
  7  2019-03-18 10:38:00  0.305353199   A  0.4045876
  8  2019-03-18 10:39:00  0.198409703   A -0.1069435
  9  2019-03-18 10:40:00 -0.048910950   A -0.2473207
  10 2019-03-18 10:41:00 -0.843233767  BB -0.7943228
  </code></pre>
  
  <p>I am trying to return the rows of column "diff" as a vector when the corresponding value of "lab" column is "A". But the condition is, for "BB" not only the corresponding diff value is dropped but also the two immediate values from upper and lower rows are also skipped. </p>
  
  <p>Of the above example, following output is expected:</p>
  
  <pre><code>&gt; res
  [1]  0.0314439 -1.2708040  0.4045876 -0.1069435
  </code></pre>
  
  <p>Can you kindly help? Thanks</p>