I have two matrices of equal dimensions $(m \times n)$. If it helps, one matrix is the raw data, while the other is transformed.

I've plotted PC1 vs PC2 for both datasets individually, but then I realized I couldn't compare directly because the principal components likely change between the two matrices.

So is there a way, in R, that I can plot matrix2 using PC1 and PC2 from matrix1?

  • 1
    $\begingroup$ As long as the dimensions are consistent, you can. This becomes a linear algebra question. If you make it an "R" question, then folks here will get truculent. $\endgroup$ – EngrStudent - Reinstate Monica Feb 10 '17 at 17:45

The prcomp function in R has a handy predict method:

a <- matrix(rnorm(1000), ncol=10)
b <- matrix(rnorm(1000), ncol=10)

model <- prcomp(a, center=T, scale=T)
b_pca <- predict(model, b)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.