Might the desired function "matord" be part of a Bioconductor package? This link https://rdrr.io/bioc/clusterSeq/src/R/associatePosteriors.R suggests that could be the case. - T. Arthur Milne