tidy_pca: Tidy Principal Component Analysis

View source: R/unsupervised-pca.R

tidy_pcaR Documentation

Tidy Principal Component Analysis

Description

Performs PCA on a dataset using tidyverse principles. Returns a tidy list containing scores, loadings, variance explained, and the original model.

Usage

tidy_pca(data, cols = NULL, scale = TRUE, center = TRUE, method = "prcomp")

Arguments

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"

Value

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

Examples

# Basic PCA
pca_result <- tidy_pca(USArrests)


# Access components
pca_result$scores
pca_result$loadings
pca_result$variance


tidylearn documentation built on Feb. 6, 2026, 5:07 p.m.