title: Create a new data frame cleaning NA and updating by column in r
body: <p>Imagine we have this data which comes from a task that represents different episodes and different things happen inside each of them. I want to make a vector out of the following logics, I would like to organize the information per trials <code>t</code> only when this is available.</p>
  <pre><code>t &lt;- c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2)
  p &lt;- c(NA,NA,NA,8,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,2,NA,NA,NA,NA,NA,NA,NA,NA)
  p_1 &lt;- c(NA,NA,NA,NA,NA,NA,NA,11,NA,13,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,8,NA,NA,NA,NA)
  b &lt;- c(NA,NA,NA,NA,NA,7,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,10,NA,NA,NA,NA,NA,NA)
  rw &lt;- c(NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,-1,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,-1)
  a &lt;- c(NA,NA,1,NA,NA,1,NA,1,NA,1,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,1,NA,0,NA,NA,NA,NA)
  is &lt;- c(NA,NA,NA,FALSE,NA,NA,NA,TRUE,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,TRUE,NA,NA,NA,NA,NA,NA,NA,NA)
  v &lt;- data.frame(t,p,p_1,b,rw,a,is)
  
  #which returns the following data frame:
  
     t  p p_1  b rw  a    is
  1  1 NA  NA NA NA NA    NA
  2  1 NA  NA NA NA NA    NA
  3  1 NA  NA NA NA  1    NA
  4  1  8  NA NA NA NA FALSE
  5  1 NA  NA NA NA NA    NA
  6  1 NA  NA  7 NA  1    NA
  7  1 NA  NA NA NA NA    NA
  8  1 NA   1 NA NA  1  TRUE
  9  1 NA  NA NA NA NA    NA
  10 1 NA  13 NA NA  1    NA
  11 1 NA  NA NA NA NA    NA
  12 1 NA  NA NA NA NA    NA
  13 1 NA  NA NA NA NA    NA
  14 1 NA  NA NA NA NA    NA
  15 1 NA  NA NA -1 NA    NA
  16 2 NA  NA NA NA NA    NA
  17 2 NA  NA NA NA NA    NA
  18 2 NA  NA NA NA NA    NA
  19 2  1  NA NA NA NA  TRUE
  20 2 NA  NA NA NA NA    NA
  21 2 NA  NA 10 NA  1    NA
  22 2 NA  NA NA NA NA    NA
  23 2 NA   8 NA NA  0    NA
  24 2 NA  NA NA NA NA    NA
  25 2 NA  NA NA NA NA    NA
  26 2 NA  NA NA NA NA    NA
  27 2 NA  NA NA -1 NA    NA
  
  </code></pre>
  <p>My end aim is to read the table and produce a data frame or a vector with the updated data at every step until the end of the episode, something that would read like this.</p>
  <pre><code>1 8 NA NA NA 1 FALSE
  1 8 NA 7  NA 1 FALSE
  1 8  1 7  NA 1 TRUE
  1 8 13 7  NA 1 TRUE
  1 8 13 7  -1 1 TRUE
  2 1 NA NA NA 1 TRUE
  2 1 NA 10 NA 1 TRUE
  2 1  8 10 NA 0 TRUE
  2 1  8 10 -1 0 TRUE
  </code></pre>
  <p>I tried to make a vector without NA and then try to join them but as rows are not the same size it does not work.</p>
  <p>I also tried, based on this <a href="https://stackoverflow.com/questions/69118099/filter-na-from-different-column-and-create-new-data-frame">solution</a> and <code>dplyr</code> but I couldn't make it work</p>
  <pre><code>
  library(dplyr)
  
  test1 &lt;- v %&gt;% filter(if_all(contains('t','p','p_1','b','rw','a','is'), Negate(is.na)))
  
  
  &gt; test1 &lt;- v %&gt;% filter(if_all(contains('t','p','p_1','b','rw','a','is'), Negate(is.na)))
  Error: Problem with `filter()` input `..1`.
  ℹ Input `..1` is `if_all(contains(&quot;t&quot;, &quot;p&quot;, &quot;p_1&quot;, &quot;b&quot;, &quot;rw&quot;, &quot;a&quot;, &quot;is&quot;), Negate(is.na))`.
  x unused arguments (&quot;b&quot;, &quot;rw&quot;, &quot;a&quot;, &quot;is&quot;)
  Run `rlang::last_error()` to see where the error occurred.
  
  </code></pre>
  <p>Any ideas?</p>
  <p>Thanks in advance!</p>