title: Error while using a defined function - Error in cut.default lengths of 'breaks' and 'labels' differ
body: <p>I am training a NAIVE BAYES Algo on a dataset. I want to convert a continous variable to categorical variable. I know about cut function. But I wanted to train the model on a different number of bins I make for that continous variable. It will take the variable and will convert the variable and uses it in the training, then it changes the bins to next number in the vector and so on, at last it outputs the accuracies with regards to the bins, through which I can choose a better bin size.</p>
  <p>I have created the following function :</p>
  <pre><code>breakdown = function(x,n){
    
    a = round((min(x)/10),0)*10
    b = round((max(x)/10),0)*10
    c = round((b-a)/n,0)
    z = seq(a,b,c)
    z = ifelse(max(z)&lt;b,append(z,max(z)+c),z)
    v = cut(x,breaks = z,labels = 1:n)
    
    return(v)
    
  }
  </code></pre>
  <p>I have tried this on a vector of x = 1:12 with bin size 2 therefore total numbers if bins = 6 which is n.</p>
  <pre><code> Error in cut.default(x, breaks = z, labels = 1:n - 1) : 
    lengths of 'breaks' and 'labels' differ 
  </code></pre>
  <p>I know what is the error. But the thing is I am unable to find where my code is going wrong.</p>
  <p>Can someone please help me with this?</p>