在PCA分析中使用因子值(使用prcomp)

时间:2019-02-27 14:49:22

标签: r dataframe prcomp

我试图弄清楚如何将因子/水平纳入我的PCA分析中。假设我有以下内容:

> 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

理论上df [,“ col1”]在df内部是数字(因为它是一个因子),因此我应该能够使用其因子值进行PCA分析。但我似乎无法弄清楚该怎么做:

> prcomp(df, center=T, scale. = T)
Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric

如何在我的PCA分析中加入col1?我应该使用另一个PCA功能吗?

0 个答案:

没有答案