r - 如何使用 Excel 文件将列标识为 PCA 的名称列?
问题描述
我是 R 的初次登台者,我想做一个 PCA。
这是我的数据集:
structure(list(Varietes.rep = c("EPS45_2", "EPS47_1", "EPS45_1", "OPM_2", "EPS41_2", "EPS46_1", "Belet_1", "EPS42_2", "BDA_2", "Osoro_1"), ASI = c(4, 6, 2, 0, 3, 5, 3, 2, 6, 2), DTSnum = c(19, 16, 18, 16, 20, 25, 22, 16, 23, 22), DTAnum = c(15, 10, 16, 16, 17, 20, 19, 14, 17, 20), Amplitude = c(9, 14, 9, 4, 7, 8, 11, 6, 10, 6), AUC = c(416.6667, 512.1622, 353.4483, 20.98765, 327.907, 288.6364, 400, 108.8608, 601.6393, 260.6557), Pourcentage.pieds.steriles.femelle = c(4, 2.27272727272727, 1.5625, 0, 5.8252427184466,7.69230769230769, 1.20481927710843, 1.0752688172043, 1.2987012987013, 2.66666666666667), Hauteur.moyenne = c(270.3676, 256.6753, 281.0508, 288.0988, 272.4674, 293.8163, 303.4189, 264.7375, 258.371, 294.4444), Hauteur.moyenne.soies =c(101.8154, 100.6533, 101.8947, 100.2716, 101.8372, 130.7391, 126.2361, 97.1125, 102.7705, 122.7097), Pourcentage.double.epis = c(29.4117647058824, 33.3333333333333, 41.1764705882353, 74.5098039215686, 15.6862745098039, 29.4117647058824, 47.0588235294118, 58.8235294117647, 27.4509803921569, 31.3725490196078)), row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"))
我的专栏名称是“Varietes.rep”,我想明确指出这个变量是我的个人,对于我的 PCA。
我能怎么做?
解决方案
在base R
中,我们可以row.names
在删除第一列的同时设置第一列并应用prcomp
prcomp(`row.names<-`(as.data.frame(df1[-1]), df1[[1]]))
-输出
Standard deviations (1, .., p=9):
[1] 1.740407e+02 1.940922e+01 1.244057e+01 4.747485e+00 2.481467e+00 1.197997e+00 3.621528e-01 1.236234e-01 4.044832e-15
Rotation (n x k) = (9 x 9):
PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9
ASI -0.009441536 -0.004237640 0.023921657 -0.19086237 -0.052048523 -0.315610214 0.20076598 0.69780588 -5.773503e-01
DTSnum -0.006867303 0.125533815 0.062339752 -0.13742720 0.558004323 -0.308139050 -0.23453973 0.40836369 5.773503e-01
DTAnum 0.002574233 0.129771455 0.038418095 0.05343516 0.610052846 0.007471164 -0.43530572 -0.28944219 -5.773503e-01
Amplitude -0.013888223 -0.004206378 -0.058284888 -0.08600605 -0.513714294 -0.075437642 -0.83548049 0.14619983 2.371367e-15
AUC -0.996727987 0.013670006 -0.075289266 0.01591253 0.008442632 -0.005448888 0.01329253 -0.01212881 0.000000e+00
Pourcentage.pieds.steriles.femelle -0.001913776 0.047541419 0.149077548 -0.08786674 -0.152057897 -0.855253847 0.08990259 -0.45291086 -1.486224e-15
Hauteur.moyenne 0.037010923 0.739041840 -0.244336259 0.59755584 -0.107680234 -0.097974355 0.04572905 0.11130594 1.144917e-16
Hauteur.moyenne.soies -0.002450546 0.624853368 0.002744968 -0.73347830 -0.078457457 0.203460007 0.07873022 -0.13343280 -3.131176e-16
Pourcentage.double.epis 0.069412039 -0.168206275 -0.950298953 -0.17718858 0.094402269 -0.131187195 0.02483250 -0.07540691 3.469447e-17
推荐阅读
- android - “IllegalStateException:systemuid 中的相同 jobid。” 安排新工作时
- r - R 数据表。在具有分组依据和条件的移动窗口上应用功能
- mysql - Mysql Group By 使用 Count 获取最新记录
- android - 来自另一个文件的 DrawerNavigator 不起作用
- ios - 关闭视图控制器时隐藏插座
- java - WebResourceResponse 无法从 HttpConnection (Android) 读取完整的输入流
- python - pyqt5应用程序中对话框和主窗口的国际化(翻译)
- angular - Angular 6/7 默认使用急切/延迟加载?
- python - 更新 Django POST 请求
- arrays - 如何将数据插入到结构中