powered by
Performs PCA on a dataset using tidyverse principles. Returns a tidy list containing scores, loadings, variance explained, and the original model.
tidy_pca(data, cols = NULL, scale = TRUE, center = TRUE, method = "prcomp")
A list of class "tidy_pca" containing:
scores: tibble of PC scores with observation identifiers
loadings: tibble of variable loadings in long format
variance: tibble of variance explained by each PC
model: the original prcomp/princomp object
settings: list of scale, center, method used
A data frame or tibble
Columns to include in PCA (tidy select syntax). If NULL, uses all numeric columns.
Logical; should variables be scaled to unit variance? Default TRUE.
Logical; should variables be centered? Default TRUE.
Character; "prcomp" (default, recommended) or "princomp"
# Basic PCA pca_result <- tidy_pca(USArrests) # Access components pca_result$scores pca_result$loadings pca_result$variance
Run the code above in your browser using DataLab