I have the matrix ABS.Matrix, which contains the absolute valute of a correlation matrix. Dimension of the matrix is 224*224.
For all variables I need to select the name of the first 10 largest correlations.
For a sigle variable I can determine it as follows:
A<-head(colnames(rbind(sort(ABS.Matrix[,2],decreasing=TRUE))),10)
B<-head(colnames(rbind(sort(ABS.Matrix[,224],decreasing=TRUE))),10)
This is for example for variable n.2 e 224.
If I do:
cbind(A,B)
I obtain a matrix where the two columns are the first 10 largest correlation variable names. I need do iterate it and obtain the same results for all the 224 variables.
I have tried:
for (k in 1:224){
X[k]=head(colnames(rbind(sort(ABS.Matrix[,k],decreasing=TRUE))),10)
}
to obtain the results for all variables but I get the error "number of items to replace is not a multiple of replacement length".
How I can do that in the correct way? There is easier way?