vendredi 24 mars 2017

State if Last Non-NA value in row exists in respective row

I have a dataframe as follows:

Col1    Col2    Col3    Col4     Col5    Col6    Col7
   A       B       C       D        E       F      NA
   J       K       L      NA       NA      NA      NA
   Z       M       T       P        M      NA      NA
   H       I       J      NA       NA      NA      NA
   A       B       C       D        B      NA      NA

How do I insert a new column stating whether or not the last non-NA value exists in that row? I would want the final output to look like this:

Col1    Col2    Col3    Col4     Col5    Col6    Col7    Exist?
   A       B       C       D        E       F      NA        No
   J       K       L      NA       NA      NA      NA        No
   Z       M       T       P        M      NA      NA       Yes
   H       I       J      NA       NA      NA      NA        No
   A       B       C       D        B      NA      NA       Yes

Aucun commentaire:

Enregistrer un commentaire