Suppose I have a matrix, mx
, with named rows and columns, with hundreds of rows/columns. A sample looks like:
ABC DEF GHI
ABC 1 0 1
DEF 0 1 0
GHI 0 0 1
And suppose I have a data frame called df
with two columns which looks like:
letters country
ABC UK
DEF USA
GHI Egypt
I want to rename the rows and columns in mx
based on the corresponding country
values in df
.
I.e. I would like mx
to become:
UK USA Egypt
UK 1 0 1
USA 0 1 0
Egypt 0 0 1
Does anyone know whether this is possible in R?