我使用r对我的数据进行了pca,我试图用大于1的特征值来保存组件.
> summary(pca1)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8
Standard deviation 1.2851803 1.1245020 1.0737268 1.0011978 0.9841687 0.88758402 0.84798807 0.67308490
Proportion of Variance 0.2064611 0.1580631 0.1441112 0.1252996 0.1210735 0.09847567 0.08988547 0.05663041
Cumulative Proportion 0.2064611 0.3645241 0.5086353 0.6339349 0.7550084 0.85348412 0.94336959 1.00000000
> loadings(pca1)
Loadings:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8
AspectRatio 0.604 0.325 0.230 0.194 0.652
CPUSpeed 0.241 0.278 0.890 -0.242
IsDvrEnabled 0.428 -0.329 -0.109 -0.290 -0.724 -0.281
ZoomMode 0.123 0.837 -0.133 -0.232 -0.124 -0.432
Tuner_BitRate 0.600 -0.272 0.392 0.161 -0.616
Tuner_Hole -0.948 0.306
Receiver_VideoDecoderErrors -0.705 0.283 -0.640
Receiver_AudioDecoderErrors -0.128 -0.690 -0.275 0.650
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8
SS loadings 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000
Proportion Var 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
Cumulative Var 0.125 0.250 0.375 0.500 0.625 0.750 0.875 1.000
Run Code Online (Sandbox Code Playgroud)
所以在这种情况下,我对前四个组件感兴趣.有没有办法可以将它保存在表格或文件中(提供文件).谢谢!
loadings(pca1)返回PCA加载.unclass删除该类并将其转换为matrix.
pca1$sdev^2 > 1返回TRUE特征值> 1 [...,drop = F]的列,选择索引等于的列,TRUE同时保留矩阵结构,即使只选择了一列.write.csv将结果写入文件.
最终守则: write.csv(x = unclass(loadings(pca1))[,(pca1$sdev^2 > 1),drop = FALSE], file = "filename.csv")