title: How to resolve "non-numeric argument to binary operator" in R?
body: <p>This is my full code:</p>
  <pre><code>library(tree)
  library(ISLR)
  attach(Carseats)
  
  High = ifelse(Sales &lt;= 8, &quot;No&quot;, &quot;Yes&quot;)
  Carseats = data.frame(Carseats, High)
  
  Carseats$var15 &lt;- NULL
  Carseats$var16 &lt;- NULL
  
  tree.carseats = tree(High~.-Sales, Carseats)
  summary(tree.carseats)
  </code></pre>
  <p>From the <strong>Carseats</strong> data frame, I just deleted two accidentally-created columns (var15 and var16, which all contained NA for all their rows. In order to reproduce this, you must create two columns var15 and var16, with NA as their inputs on rows, at the last indexes.</p>
  <pre><code>Carseats$var15 &lt;- NULL
  Carseats$var16 &lt;- NULL
  </code></pre>
  <p>After which, my code for summary(tree.carseats) outputs the following error message:</p>
  <pre><code>Error in y - frame$yval[object$where] : non-numeric argument to binary operator
  </code></pre>
  <p>I am supposed to be getting the following output when I run the summary(tree.carseats):</p>
  <pre><code>Classification tree: tree(formula = High ∼ . - Sales , data = Carseats ) 
  Variables actually used in tree construction:
  [1] &quot;ShelveLoc &quot; &quot;Price&quot; &quot;Income&quot; &quot;CompPrice &quot;
  Test Classification Error
  0.05 0.10 0.15 0.20 0.25
  [5] &quot;Population &quot; &quot;Advertising &quot; &quot;Age&quot; &quot;US&quot; Number of terminal nodes: 27
  Residual mean deviance: 0.4575 = 170.7 / 373 Misclassification error rate: 0.09 = 36 / 400
  </code></pre>
  <p>Also take note I receive the warning message when running tree(High ~ . - Sales, Carseats)</p>
  <pre><code>1: In tree(High ~ . - Sales, Carseats) : NAs introduced by coercion
  2: In tree(High ~ . - Sales, Carseats) : NAs introduced by coercion
  </code></pre>
  <p>In order to reproduce this, you must create 2 additional columns from the Carseats data. I    have no idea how I accidentally made the 2 unnecessary columns, but I believe how I removed them using the code above is the culprit of the error message. Kindly help, thank you.</p>