I have a data.frame that looks like this:
PC1 PC2 PC3 PC4 PC5
TGFBI 0.05105828 0.04259313 0.001931321 -0.014739818 -0.023630707
OLFM4 -0.01093027 -0.07768484 -0.056874220 -0.011045101 -0.009762945
CD177 -0.03543697 -0.05385507 -0.073857334 0.024278031 0.009186970
LCN2 -0.01539785 -0.07883489 -0.036711308 0.014314281 -0.010042372
CEACAM8 -0.01130204 -0.08092082 0.004004276 -0.003607281 -0.008600472
This is the output of myPCAdf$rotation
. I would like to sort each PC using abs values and then I would like to subset the top n-genes. If I perform:
data.frame(sort(abs(myPCAdf$rotation[,"PC4"]), decreasing=TRUE)[1:50])
I obtain the list of values loosing the name of the genes. Can anyone help to obtain a data.frame containing two columns for each PC: one containing the name of genes resulting form the sort of the numerical values in the second column.
Thank you in advance.
Desired output (short example):
PC1
TGFBI 0.05105828
HLA-DPB1 0.04843209
OLFM4 -0.01093027
CEACAM8 -0.01130204
LCN2 -0.01539785
CD177 -0.03543697
.............