. Advertisement .
..3..
. Advertisement .
..4..
I am new to r and searching the “error in colmeans(x, na.rm = true) : ‘x’ must be numeric” to understand it better. It seems it doesn’t work as expected when I used some suggestions before. This is the command line I use:
data(birth.death.rates.1966)
data2 <- birth.death.rates.1966
princ <- prcomp(data2)
The error I’m getting is below:
Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric
Please give me the solution for this issue.
factor
allows you to convert a vector of characters into numeric values. Each unique value then gets an unique integer code. This example shows four values. The numbers 1 through 4 are alphabetical.Then, you can run
prcomp
It is up to the application whether this makes sense. You might just want to remove
prcomp(d[,-1])
from the first column and instead work with numeric data.The character is the first column in the data frame. You can also recode the data frame to create row names like:
Alternately, you can also use: