0
votes

I have marker data (as matrix) marker, where rownames are names of the individuals and colnames are names of the markers.

marker <- 
              BBLM062 BBLM00182 BBLMOO587.......
ALEN294945     AA  AA  AT ....
ALEN29394      AT  AA  TT ....
ALEN49494888   AT  AA  TT ....
ALEN26424      AA  AA  AA ....
ALEN38764      AA  AT  AA ....
ALEN29794      AA  AT  AA ....
......
(282 x 1082)

I have another dataset pheno (also as a matrix) where rownames are names on indviduals colnames are names of the traits

pheno <-
              height weight colour ......
ALEN26494     162  3.5  3
ALEN49494888  154  3.8  5
ALEN494967    131  4.0  5
ALEN49678     152  3.9  7
ALEN294945    138  4.9  1
.......
(260 x 7)

all the individuals in 'pheno' are also present in 'marker' but not in the same order. I have 3 questions

  1. How to subset 'marker' based on the rownames of 'pheno' or exclude the individuals from 'marker' that are not present in 'pheno';
  2. How to reorder the individuals in 'pheno' based on 'marker' or vice-versa (I have marker data from another population 'marker2' with 900 markers - colnames are marker names;
  3. How do I subset 'marker' based on colnames or 'marker2' and reorder them as we did in question 2

Thanks in advance .

1

1 Answers

0
votes

You will get a lot more help if you share reproducible examples. You can use the dput( ) function to help share your data.

you can subset with this code:

marker[row.names(marker) %in% row.names(pheno),]