I have the following extract of my dataset:

```
basisanddowngradessingledates[1716:1721, ]
# A tibble: 6 x 23
   Dates                   Bank     CDS     Bond     `Swap zero rate`   `CDS-bond basis` `Basis change` `Rating agency`
  <dttm>                  <chr>  <dbl>    <dbl>            <dbl>            <dbl>          <dbl>           <chr>
1 2015-05-15 Allied Irish Banks PLC 129.63 201.0235             40.6        -30.79352      1.9408116              NA
2 2015-05-18 Allied Irish Banks PLC 129.64 202.1998             41.0        -31.55976     -0.7662374              NA
3 2015-05-19 Allied Irish Banks PLC 129.65 200.4579             39.0        -31.80792     -0.2481631           Fitch
4 2015-05-20 Allied Irish Banks PLC 129.65 203.9960             39.0        -35.34598     -3.5380550            DBRS
5 2015-05-21 Allied Irish Banks PLC 129.63 203.5341             41.0        -32.90415      2.4418300              NA
6 2015-05-22 Allied Irish Banks PLC 130.64 203.2723             40.0        -32.63234      0.2718045              NA

```

I would like to select the intervals [-1:1], which corresponds to the day before and the day after a downgrade. At the row where the column "Rating agency" is not "NA" indicates that a downgrade has occured. In my example above, rows [1717:1719] and [1718:1720], so 6 rows, for each downgrade 3.

My dataset has 45276 entries with 536 downgrades (column "Rating agency" is not "NA") where I would like to build a list containing the 3 rows where a downgrade occured.

I tried it using the following code:

```
keepindex <- which(basisanddowngradessingledates[,8] != "NA")
interval11 <- unique(c(keepindex-1, keepindex, keepindex+1))
interval1ra1 <- basisanddowngradessingledates[interval11,]

```

This works if there are no downgrades on consecutive days. However in my example extract I have two downgrades right after each other and I get the following output:

```
print(interval1ra1[c(11:12, 348, 674), ])
# A tibble: 4 x 23
   Dates                   Bank    CDS     Bond      `Swap zero rate` `CDS-bond basis` `Basis change` `Rating agency`
  <dttm>                  <chr>  <dbl>    <dbl>            <dbl>            <dbl>          <dbl>           <chr>
1 2015-05-18 Allied Irish Banks PLC 129.64 202.1998               41        -31.55976     -0.7662374              NA
2 2015-05-19 Allied Irish Banks PLC 129.65 200.4579               39        -31.80792     -0.2481631           Fitch
3 2015-05-20 Allied Irish Banks PLC 129.65 203.9960               39        -35.34598     -3.5380550            DBRS
4 2015-05-21 Allied Irish Banks PLC 129.63 203.5341               41        -32.90415      2.4418300              NA

```

I get 4 rows instead of 6 which I need.

I guess the `unique()`function prevents duplicate rows, but in my example I need these rows as described above. 

How can I fix this?