Learn R Programming

ribiosPlot (version 1.3.0)

pcaScores: Retrieve PCA scores from prcomp objects

Description

Retrieve PCA scores from prcomp objects

Usage

pcaScores(x, choices, offset, reverse = c(FALSE, FALSE))

Value

A PCAScoreMatrix object containing the PCA scores.

Arguments

x

An object of prcomp

choices

Integer vector, indices of principal components, default the first two PCs. If missing, NULL or NA, all PCs are returned.

offset

Oither one or more rows's names in the loading matrix, or indices, or a logical vector. The average loading of the rows specified by offset is set to zero.

reverse

Logical of the same length as choices or 1 (which will be repeated), indicating whether the sign of values in the indexed axis should be reversed

Examples

Run this code

testMatrix <- matrix(rnorm(1000), nrow=10)
testPCA <- prcomp(testMatrix)
testPCAscores <- pcaScores(testPCA)

testPCAscores.withOffset <- pcaScores(testPCA, offset=c(1,3,5))
## notice the average of offset-rows are near zero
colMeans(as.matrix(testPCAscores.withOffset)[c(1,3,5),])

testPCAscores.withReverse <- pcaScores(testPCA, reverse=c(TRUE, FALSE))
colMeans(as.matrix(testPCAscores.withReverse)[c(1,3,5),])

Run the code above in your browser using DataLab