title: R - Writing a function to return binary output using if statement
body: <p>Good day,</p>
  
  <p>I am a beginner and trying to understand why I am getting the error below.</p>
  
  <p>I am trying to create a function that would return 0 or 1 based on column values in data set.</p>
  
  <pre><code>LT = function(Lost.time) {
      For (i in 1:dim(df)) {
          if (df$Lost.time &gt; 0) {
              x = 1
          }
          else {
              x = 0
          }
          return(x)
      }
  }
  </code></pre>
  
  <p>Error: no function to return from, jumping to top level In addition: Warning
       message: In if (df$Lost.time > 0) { : the condition has length > 1 and only 
     the first element will be used> } Error: unexpected '}' in "}"</p>