Reputation: 1069
I have a matrix whose column names I switch around, but, when I do so, the columns reorder themselves. For example:
BGASBK BTICFR
becomes
CFRBTI SBKBGA
(because I have switched the first three letters and the last 3 letters around)
I would, however, like for the new ordering to be the same as the original ordering i.e.
SBKBGA CFRBTI
In reality there are more than columns though.
Any help would be greatly appreciated!
Thanks
Mike
Upvotes: 0
Views: 62
Reputation: 121568
Why not to store the original order in a column and use it to reorder your final result? Something like this :
A <- data.frame(a=c("BGASBK","BTICFR"),
b=c("SBKBGA","CFRBTI"))
## I store the order of the column a to be used later
A$ord <- order(A$a) ## here you can use many columns order(col1,col2,..)
Now if I have B <- A[order(A$b),]
sotred by b , I can reorder it using ord column:
B[order(B$ord),]
Upvotes: 1