I am trying to figure out how I can incorporate the factor/levels into my PCA analysis. Suppose I have the following:
> df <- data.frame(col1=c("A", "B", "C", "D"), col2=c(1, 2, 3, 4))
> str(df)
'data.frame': 4 obs. of 2 variables:
$ col1: Factor w/ 4 levels "A","B","C","D": 1 2 3 4
$ col2: num 1 2 3 4
Theoretically df[,"col1"] is numeric internally in the df (since it is a factor) so I should be able to use its factor values for PCA analysis. But I can't seem to figure out how I can do it:
> prcomp(df, center=T, scale. = T)
Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric
How can I include col1
in my PCA analysis? Is there another PCA function I should be using?