title: returning null using ifelse function
body: <p>I am trying to return null using ifelse in R. But it throws an error message. Any suggestion please.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>cntr1 &lt;- ifelse(unlist(gregexpr("---",path_info[j], fixed = TRUE, useBytes = TRUE)) &gt; 0, 3 * length(unlist(gregexpr("---",path_info[j], fixed = TRUE, useBytes = TRUE))),NULL )
  </code></pre>
  
  <p>Error message is:</p>
  
  <pre><code>Error in ifelse(unlist(gregexpr("---", path_info[j], fixed = TRUE, useBytes = TRUE)) &gt;  : 
    replacement has length zero In addition: Warning message:
  In rep(no, length.out = length(ans)) :
    'x' is NULL so the result will be NULL
  </code></pre>