title: Get Value of last non-empty column for each row
body: <p>Take this sample data:</p>
  
  <pre><code>data.frame(a_1=c("Apple","Grapes","Melon","Peach"),a_2=c("Nuts","Kiwi","Lime","Honey"),a_3=c("Plum","Apple",NA,NA),a_4=c("Cucumber",NA,NA,NA)) 
  
     a_1    a_2   a_3     a_4
  1  Apple  Nuts  Plum    Cucumber
  2 Grapes  Kiwi  Apple    &lt;NA&gt;
  3  Melon  Lime  &lt;NA&gt;     &lt;NA&gt;
  4  Peach  Honey  &lt;NA&gt;    &lt;NA&gt;
  </code></pre>
  
  <p>Basically I want to run a grep on the last column of each row which is not NA. Thus my x in grep("pattern",x) should be:</p>
  
  <pre><code>Cucumber
  Apple
  Lime
  Honey
  </code></pre>
  
  <p>I have an integer which tells me which a_N is the last one:</p>
  
  <pre><code>numcol &lt;- rowSums(!is.na(df[,grep("(^a_)\\d", colnames(df))])) 
  </code></pre>
  
  <p>So far I have tried something like this in combination with ave(), apply() and dplyr:</p>
  
  <pre><code>grepl("pattern",df[,sprintf("a_%i",numcol)])
  </code></pre>
  
  <p>However I dont quite can make it work. Keep in mind that my dataset is very large thus I was hoping vor a vectorized solution or mb dplyr. 
  Help would be greatly appreciated. </p>
  
  <p>/e: Thanks, that is a really good solution. My thinking was too complicated. (the regex is due to my more specific data )</p>