Search code examples
reigenvector

pca - which eigenvector corresponds to which eigenvalue


I am to do as follows: I have a set of Vektors v1-vn For these, I need the covariance matrix (which I get while doing a pca). I also need the eigenvalues and eigenvectors of the covariance matrix. The eigenvalues I sort in descending order and then I sort the eigenvectors according to their corresponding eigenvalues. After that I multiply v1 with the first of the eigenvectors, v2 with the second and so on. I return the skalar which I get in this way.

Is there any simple way in R to see which eigenvalue corresponds to which eigenvector?


Solution

  • Use the result of prcomp directly. It sorts the eigenvalues from biggest to smallest.

     p <- prcomp(USArrests, scale=T)
    

    For appropriate values of i, the eigenvalue is p$sdev[i]^2, with eigenvector p$rotation[,i]