user1862770
user1862770

Reputation: 317

how to use (after a pca) just one vector in an object?

I feel like kind of a noop.....

Well I have a pca (I have used prcomp) and I am looking for the eigenvectors of the covaricance matrix. I know I get those using rotation. rotation gives me a matrix composed of the eigenvectors. But if I want to print (or use for any other purpose) only one of those eigenvectors: how do I call it? I know I can print all of them by using print (mypcqobject$rotation) but what if I only want one?

Upvotes: 0

Views: 229

Answers (1)

Matthew Lundberg
Matthew Lundberg

Reputation: 42639

You would subset the $rotation object. Which vector do you want?

> prcomp(USArrests, scale=T)$rotation[1,]    # Murder row
       PC1        PC2        PC3        PC4 
-0.5358995  0.4181809 -0.3412327  0.6492278 
> prcomp(USArrests, scale=T)$rotation[,1]    # PC1 column
    Murder    Assault   UrbanPop       Rape 
-0.5358995 -0.5831836 -0.2781909 -0.5434321 

Upvotes: 2

Related Questions