Metabolomics Society Forum

Software => R => Topic started by: genefisher on June 27, 2019, 02:48:51 PM

Title: Help on PCA: Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric
Post by: genefisher on June 27, 2019, 02:48:51 PM
Hi,
Any body knows how to solve this R PCA problem? I`ve try many times, I still don`t know the reason. I hope somebody could help me
When I type:
> dtp<-prcomp(tdt,retx= TRUE,center= TRUE,scale= TRUE)
Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric

Thanks in advance for all your help.
Title: Re: Help on PCA: Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric
Post by: ManjotV on June 28, 2019, 08:31:50 AM
Hello,
One of your columns contains non-numeric information. This might be because your data frame (tdt) has a column specifying the treatment. Here is an example with the iris data set which has "Species" in column 5.

data("iris")
pca <- prcomp(iris)  # Fails with "Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric"
pca <- prcomp(iris[1:4])  # Success

Hope this helps.