Copy rows of a df when NA == TRUE plus upper and lower rows in R
<p>Not sure if the title is clear enough. I have the following dataframe: (ST.final is the name of the df)</p>

<pre><code>n;date;ws;wd
1;2011-11-01 00:00:00;7,15;113,7
2;2011-11-01 00:10:00;7,25;115,7
3;2011-11-01 00:20:00;NA;NA
4;2011-11-01 00:30:00;NA;NA
5;2011-11-01 00:40:00;7,2;100,7
6;2011-11-01 00:50:00;6,95;104,7
</code></pre>

<p>And I want to create a new one with the rows containing NAs plus the upper and lower limit rows. The result should be something like this:</p>

<pre><code>n;date;ws;wd
2;2011-11-01 00:10:00;7,25;115,7
3;2011-11-01 00:20:00;NA;NA
4;2011-11-01 00:30:00;NA;NA
5;2011-11-01 00:40:00;7,2;100,7
</code></pre>

<p>Maybe I am missing something but I have no clue on how to perform this task. So far I am trying to use this</p>

<pre><code>interp.df &lt;- ST.final[(is.na(ST.final$ws)),]
</code></pre>

<p>and as expected it just copy every row containing NAs. I searched for a solution on google but couldnt find anything similar.</p>

<p>Any help is appreciated.</p>