title: R - select only factor columns of dataframe
body: <p>I am trying to select only factor columns from my data frame. Example is below:</p>
  
  <pre><code>bank[,apply(bank[,names(bank)!="id"], is.factor)]
  </code></pre>
  
  <p>But the code behaves strangely. Step by step:</p>
  
  <pre><code>sapply(bank[,names(bank)!="id"], is.factor)
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>age         sex      region      income     married    children         car 
        FALSE        TRUE        TRUE       FALSE        TRUE       FALSE        TRUE 
     save_act current_act    mortgage         pep      ageBin 
         TRUE        TRUE        TRUE        TRUE        TRUE 
  </code></pre>
  
  <p>Looks OK. Now, I assume that I just pass this matrix of TRUE/FALSE to the next step and get only the columns I need:</p>
  
  <pre><code>bank[,sapply(bank[,names(bank)!="id"], is.factor)]
  </code></pre>
  
  <p>But as result I get all the same columns as in original bank dataframe. Nothing is filtered out. I tried it one way or another but can't find a solution. Any advice on what I am doing wrong?</p>