hi o all i have data like this

    Ind	M1	M2	M3	M4	M5
    P1	A/A	Unused	G/A	T/T	T/T
    P2	T/T	A/A	A/A	A/A	G/G
    1	T/A	A/A	G/A	T/T	G/G
    2	T/T	A/A	G/A	T/T	T/G
    3	T/T	A/A	G/A	T/T	T/G
    4	T/T	A/A	G/A	A/T	G/G
    5	T/A	A/A	G/A	A/T	T/G

First:i want to check whether P1 and P2 match each other for M1 or not, if they not matched(like P1=A/A,P2=T/T) that column should be selected and write in outfile, like this i want to do for remaining columns till M5 2nd step: Now in outputfile I want to match M1 value of 1st individual to P2, if it match then 1 otherwise it will be 0, M1 value is between them like (A/T ) then it will be H and so on for M4 and M5 3rd step: Then I will sum all the 1's and H' 
finally my output will look like this

    Ind	M1	M4	M5		
    P1					
    P2				SUM of 1's	SUM OF H
    1	H	0	1	     1	                   1
    2	1	0	H	     1	                   1
    3	0	0	H	     0	                   1
    4	1	H	1	     2	                   1
    5	H	H	H	     0	                   3

I am just beginner in R but till now i am doing this work in excel with sumif and countifs functions but now i can not do this work in excel because of column limitations. can any one help me to sort out this? any help in this regard will be highly appreciated. Here is my file for better understanding dropbox.com/s/ft943u7rf6v9j4b/row%20match.xlsx?dl=0 
thanks in advance


Dear Friederike

Thank you very much for your kind and prompt reply to my request. I just modified your code little bit, till last step it is working fine but finally I am unable to format off_par. Now I am sharing my data file (https://www.dropbox.com/s/tysf6p3xdin9lop/biostars.xlsx?dl=0) and code I tried here (https://www.dropbox.com/s/l4ez5ht7i3o6xmd/Friederike%20Code.txt?dl=0) here for better understanding.
With kind regards,