View source: R/unsupervised-pca.R
| tidy_pca | R Documentation |
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")
data |
A data frame or tibble |
cols |
Columns to include in PCA (tidy select syntax). If NULL, uses all numeric columns. |
scale |
Logical; should variables be scaled to unit variance? Default TRUE. |
center |
Logical; should variables be centered? Default TRUE. |
method |
Character; "prcomp" (default, recommended) or "princomp" |
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
# Basic PCA
pca_result <- tidy_pca(USArrests)
# Access components
pca_result$scores
pca_result$loadings
pca_result$variance
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.