【发布时间】:2018-01-27 18:36:34
【问题描述】:
我正在尝试使用 prcomp 对一组数据进行 PCA
SS.chem<-read.csv("PCASS3.csv")
SS.pca <- prcomp(SS.chem,
center = TRUE,
scale. = TRUE)
返回以下错误
> SS.pca <- prcomp(SS.chem,
+ center = TRUE,
+ scale. = TRUE)
Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric
但是,当我测试以确保我的数据是数字时,它们...是?
sapply(SS.chem, class)
Capture.zone X_.18O.NO3 X_.15N.NO3 NO3.T
"numeric" "numeric" "numeric" "numeric"
WellDepth PopDens Pop DepthToUfa
"numeric" "numeric" "numeric" "numeric"
SOM. Clay. ConfineThick LUDom
"numeric" "numeric" "numeric" "numeric"
ostdscount Ag. Barren. Forest.
"numeric" "numeric" "numeric" "numeric"
Transportation. UplandNonforest. Urban. Wetland.
"numeric" "numeric" "numeric" "numeric"
GolfCourses. ImprovedPasture. FieldCrops. Citrus.
"numeric" "numeric" "numeric" "numeric"
Ornamental. HorseFarm. Sewage.
"numeric" "numeric" "numeric"
我有什么遗漏吗?为什么它仍然给我这个错误?
编辑:这是我的几行数据
> str(SS.chem)
List of 27
$ Capture.zone : num [1:48] 1000 1000 1000 1000 1000 100 2 1000 2 2 ...
$ X_.18O.NO3 : num [1:48] 9.23 7.74 10.75 5.37 0 ...
$ X_.15N.NO3 : num [1:48] 10.67 6.78 9.53 7.88 3.03 ...
$ NO3.T : num [1:48] 0.49 0 0.01 0.38 0.04 0 0.02 1.73 0.25 ...
$ WellDepth : num [1:48] 0 190 132 0 0 0 0 0 0 0 ...
$ PopDens : num [1:48] 246.092 1.102 21.331 246.092 0.359 ...
$ Pop : num [1:48] 313.417 1.404 27.166 313.417 0.457 ...
$ DepthToUfa : num [1:48] 121.9 107.9 79.1 121.9 36.4 ...
$ SOM. : num [1:48] 1.12 1.23 1.23 1.12 60 ...
$ Clay. : num [1:48] 3.5 3.5 3.5 3.5 3 ...
$ ConfineThick : num [1:48] 85.1 91.4 61.7 85.1 0 ...
【问题讨论】:
-
你能显示几行数据吗?
-
发布了一些数据的更新
-
数据结构显示为列表,先转成数据框。