Dear all,

I wonder if you may point me in the right direction with a problem I have?

I have a matrix with pairwise estimates like this (note: individual names are not in order):

obs ind4 ind1 ind7 ind5 ...

ind3 0.2

ind2 0.3 0.1

ind4 0.2 0.4 0.2

...

I would like to reorder that matrix based in individual ID so that both columns and rows are in alphabetical order, and the values still only in the lower triangle of the matrix:

obs **ind1** **ind2** **ind3** **ind4** ...

**ind2** 0.1

**ind3** 0.5 0.1

**ind4** 0.2 0.4 0.2

...

I have already tried to sort it in Linux with simple

- sort by line
- transpose matrix
- sort by line again,

but this gives me a matrix with the values all over the place (instead of in the lower triangle).

I have searched for appropriate commands in tidyverse, but have so far only found ways to sort a file based on a certain column (NOT on all column AND all line names)...

Do you know of a way I can get the matrix in the desired order?

many thanks in advance and best regards,

Katharina

(as I don't even know with which tidyverse command to start, I cannot provide a reproducible example)