This should be simple, but I cannot figure it out:
I have a square matrix with integer values in each cell (result of an all vs all distance calculation). I would like to subset the matrix based on the cell values, e.g. cell == 8, or cell <= 6 , etc.
foo[1:5, 1:5]
CASSLLAGAPEQFF CASSQVGLATGTQYF CASSSGTQYTQYF CASRITSGGKTQYF CATSDSRGKTQYF
CASSLLAGAPEQFF 0 999 999 8 999
CASSQVGLATGTQYF 999 0 999 999 999
CASSSGTQYTQYF 999 999 0 999 6
CASRITSGGKTQYF 8 999 999 0 999
CATSDSRGKTQYF 999 999 6 999 0
dput:
structure(c(0, 999, 999, 8, 999, 999, 0, 999, 999, 999, 999, 999, 0, 999, 6, 8, 999, 999, 0, 999, 999, 999, 6, 999, 0), .Dim = c(5L, 5L), .Dimnames = list(c("CASSLLAGAPEQFF", "CASSQVGLATGTQYF", "CASSSGTQYTQYF", "CASRITSGGKTQYF", "CATSDSRGKTQYF"), c("CASSLLAGAPEQFF", "CASSQVGLATGTQYF", "CASSSGTQYTQYF", "CASRITSGGKTQYF", "CATSDSRGKTQYF" )))
Expected result of cell == 8 would be a 2x2 matrix of
CASSLLAGAPEQFF CASRITSGGKTQYF
CASSLLAGAPEQFF 0 8
CASRITSGGKTQYF 8 0
The row and column names don't matter to the subsetting (but I want to keep the names). What is the most straightforward way to do that?
Thanks for your help!
dput
to show a small example of what you have. When you say "all vs all distance calculation" do you mean you've useddist
and now have an object of class dist? – Rolanddput(foo[1:5, 1:5])
to the question and also show the expected result. – Roland