title: Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric even after convert them to numerical variables
body: <p>I have just started to learn R few days ago. I'm trying to run PCA using R (ver. 4.0.3) under R console based on the tutorial here (<a href="https://www.benjaminbell.co.uk/2018/02/principal-components-analysis-pca-in-r.html#further" rel="nofollow noreferrer">https://www.benjaminbell.co.uk/2018/02/principal-components-analysis-pca-in-r.html#further</a>)</p>
  <p>My data consists of 2 categorical variables (<code>SPECIES</code> &amp; <code>STATE</code>) and 4 numeric variables, and the categorical variables are important to my PCA and cannot be removed.</p>
  <p>I loaded my excel data (<strong>dataset1.csv</strong>) as <strong>dataset2</strong> and I tried converting them to numerical variables using:</p>
  <pre><code>#1
  d = data.frame(Species=c(&quot;EA&quot;, &quot;EH&quot;, &quot;ES&quot;), x=runif(3), y=runif(3))
  
  #2
  d$Species = as.numeric(as.factor(d$Species))
  
  #3
  3. d = data.frame(State=c(&quot;Kelantan&quot;, &quot;Terengganu&quot;, &quot;Pahang&quot;, &quot;Johor&quot;), x=runif(4), y=runif(4))
  
  #4
  d$State = as.numeric(as.factor(d$State))
  </code></pre>
  <p>See tutorial: <a href="https://stackoverflow.com/questions/44172274/principal-components-analysiserror-in-colmeansx-na-rm-true-x-must-be-n">Principal Components Analysis:Error in colMeans(x, na.rm = TRUE) : &#39;x&#39; must be numeric</a></p>
  <p>However, when I use the code: <code>p &lt;- prcomp(dataset2)</code>, I'm still getting the error:</p>
  <blockquote>
  <p>Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric</p>
  </blockquote>
  <p>Any helps in enabling me to run PCA using both categorical and numeric variables are much appreciated.</p>
  <p>P/S: I have previously worked with FactorMineR and Factoshiny but I don't see the option to help me labelled states as different icons and species by different colors, etc.</p>