Skip to content

Instantly share code, notes, and snippets.

@monogenea
Created October 7, 2019 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monogenea/d9a37c2fd7b9a33c876e2960bdb92c3c to your computer and use it in GitHub Desktop.
Save monogenea/d9a37c2fd7b9a33c876e2960bdb92c3c to your computer and use it in GitHub Desktop.
# Generate scaled 4*5 matrix with random std normal samples
set.seed(101)
mat <- scale(matrix(rnorm(20), 4, 5))
dimnames(mat) <- list(paste("Sample", 1:4), paste("Var", 1:5))
# Perform PCA
myPCA <- prcomp(mat, scale. = F, center = F)
myPCA$rotation # loadings
myPCA$x # scores
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment