title: The apply function returns "Error: $ operator is invalid for atomic vectors"
body: <p>I have a data frame called 'bank' like below, it has around 40K rows</p>
  
  <pre><code>  age  job      salary marital education targeted default balance housing loan contact day month
    58 management 100000 married  tertiary      yes      no    2143     yes   no unknown   5   may
  
    duration campaign pdays previous poutcome response
         261        1    -1        0  unknown       no
  </code></pre>
  
  <p>I created the following function that checks some conditions and then returns a value that gets added as a new value under a new column called 'new'.</p>
  
  <pre><code>decide &lt;- function(x){
    if(x$marital=='married' &amp; x$salary &gt; 60000 &amp; x$housing=='yes'){
      return('yes') 
    }else if(x$marital=='single' &amp; x$salary &gt; 40000 &amp; x$education=='tertiary'){
      return('yes') 
    }else{
      return('no') 
    }
  }
  </code></pre>
  
  <p>Then I would use the below loop to run over all the rows and derive the new value</p>
  
  <pre><code>for(i in 1:nrow(bank)){
    person&lt;-bank[i,]
    bank[i,'new']&lt;-decide(person)
  }
  </code></pre>
  
  <p>This satisfies my requirement.</p>
  
  <p>However when I try to use an apply function instead of a for loop like below,</p>
  
  <pre><code>bank$new1&lt;-sapply(bank,decide)
  </code></pre>
  
  <p>it returns the below error </p>
  
  <blockquote>
    <p>Error: $ operator is invalid for atomic vectors</p>
  </blockquote>
  
  <p>What is the issue with the apply function I wrote, can I ask you to write the correct apply function that works like the for loop ?</p>