title: Several problems encountered when doing Discriminant analysis in R
body: <p>I encountered some problems when when doing Discriminant analysis in R.</p>
  
  <p>The first one was that when I finished the LDA analysis using the package MASS, I can't plot it. The error was:</p>
  
  <pre><code>Error in scale.default(X, center = means, scale = FALSE) : 
  length of 'center' must equal the number of columns of 'x'
  </code></pre>
  
  <p>Some part of the code：</p>
  
  <pre><code>library(MASS)
  varaslda&lt;-lda(class~rail+eco+class)
  varaslda
  plot(varaslda)
  </code></pre>
  
  <p>Another problem was that somehow I couldn't predict the class using the LDA model I already generated. The error was:</p>
  
  <pre><code>&gt; class.pre&lt;-predict(varaslda)$class
  Error in predict.lda(varaslda) : wrong number of variables
  </code></pre>
  
  <p>Can anybody help me solve these problems? Thank you.</p>