#create a data frame and then sort it in lexicographic order
set.seed(42)
x <- matrix(sample(1:4,64,replace=TRUE),ncol=4)
dfOrder(x) # sort by all columns
dfOrder(x,c(1,4)) #sort by the first and 4th column
x.df <- data.frame(x)
dfOrder(x.df,c(1,-2)) #sort by the first in increasing order,
#the second in decreasing order
#now show sorting correlation matrices
r <- cor(sat.act,use="pairwise")
r.ord <- dfOrder(r,columns=c("education","ACT"),ascending=FALSE)
psych::corPlot(r.ord)
Run the code above in your browser using DataLab