title: R - Function over rows of dataframe error True/False
body: <p>Trying to create a function that if a != b then it return b else returns a null value then cbind this to the original dataframe.</p>
  <p>However getting the following errors:
  &quot;argument is of length zero&quot;</p>
  <p>Would appreciate any help - similar function in python works fine.</p>
  <p>DataFrame is pretty simple</p>
  <p>colid col1 col2.  expected output</p>
  <ol>
  <li>
  <pre><code>     Blue  Blue
  </code></pre>
  </li>
  <li>Blue  Blue  Null</li>
  <li>Red   Blue  Blue</li>
  <li>
  <pre><code>           Null
  </code></pre>
  </li>
  </ol>
  <pre><code>library(readr)
  library(tidyverse)
  library(purrr)
  
  df &lt;- read_csv('/Users/david/Downloads/trustdata.csv')
  df_dups &lt;- df[!duplicated(df), ]
  
  wins = function(a,b) {
    if(NULL) return(NULL)
    else if(a != b) {return (b)}
    else {return (&quot;NULL&quot;)}
  }
  
  
  df_wins &lt;- apply(df, 1, function(x) wins(x[&quot;col1&quot;],x[&quot;col2&quot;])) ```
  </code></pre>