Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compute PCA in R with built-in prcomp function
#-------------------------------------------------------------------------------
# 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