Extract PC scores from a PCA result and add them to a tibble.
Usage
# S3 method for class 'stat_pca'
collect(x, data = NULL, retain = NULL, fold = FALSE, ...)Arguments
- x
A
stat_pcaobject- data
A tibble. If NULL, uses the original data from the PCA.
- retain
How many PCs to retain:
NULL(default): All PCsInteger (e.g.,
5): First N PCsNumeric 0-1 (e.g.,
0.95): PCs explaining this proportion of variance
- fold
How to add PC scores:
FALSE(default): Add as separate columns (PC1,PC2, ...)TRUE: Fold into single list-column named"pca"Character: Fold into single list-column with this name
- ...
Additional arguments (reserved)
Details
The retain parameter allows flexible selection of PCs:
retain = NULL: Keep all PCsretain = 5: Keep first 5 PCsretain = 0.95: Keep PCs explaining 95% of varianceretain = 1: Keep only PC1
When fold = TRUE or a character name, PC scores are stored as a list-column
with class c("pca", "coe"), making them usable in downstream analyses.
