Created
August 13, 2018 15:33
-
-
Save mick001/9b8058dbd8ac410cab9a1d4e63aafdef to your computer and use it in GitHub Desktop.
Compute PCA in R with built-in prcomp function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------------------- | |
# With built-in prcomp function: | |
# Compute PCA | |
pc <- prcomp(D, center = T, scale. = T) | |
# Eigenvalues | |
(pc$sdev^2)[1:20] | |
# Eigenvectors (loadings) | |
pc$rotation[, 1:20] | |
# New features (principal components, also called scores) | |
pc$x[, 1:20] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment