Add a column in dataframe based on another column

Hi

I have two dataframe and the " IID " in A and " X " in B are same but order is not.
I want to add column " phenotype " of B into A according to column IID.
how can I do it?

dataframe A

Herd.when.genotyped X IID X.2 X.3 X.4 X.5 Herd.born.in
String Int64 Int64 Int64 Int64 Int64 Int64 String
1 10041 0 412485541 412301635 410265426 2 -9 10041
2 10041 0 411679484 412301206 410763797 2 -9 10041
3 10041 0 412447988 412301927 412007106 2 -9 10041
4 10041 0 412462041 412301974 411697516 2 -9 10041
5 10041 0 410230957 412301866 408789139 2 -9 10041
6 10041 0 412492631 412301972 408789139 2 -9 10041
7 10041 0 412543616 412301961 410240054 2 -9 10041
8 10041 0 409809986 412301206 410598606 2 -9 10041
9 10041 0 412470980 412301923 409906717 2 -9 10041
10 10041 0 412473967 412301946 410401245 2 -9 10041
11 10041 0 410780712 412301355 409679783 2 -9 10041
12 10041 0 412720229 0 0 2 -9 10041
13 10041 0 412467596 412301927 410655683 2 -9 10041
14 10041 0 411065373 412301845 410240054 2 -9 10041

dataframe B

X Phenotype
Int64 Float64
1 409859435 -2.72553
2 409922125 1.45445
3 411075330 0.735245
4 412057132 0.78618
5 404693736 0.808009
6 404880845 -1.22615
7 405021206 1.6335
8 405050763 0.77081
9 405061972 0.729143
10 405081272 3.60625
11 407123971 -1.97556
12 408672181 -4.40418
13 408796084 -2.38459
14 408961344 -0.991621
15 408980544 -2.16643
16 409008076 3.44803
17 409057560 -3.55253
18 409124877 -1.11674
19 409304952 -3.14657
leftjoin(A, B, on = "IID")

?

@pdeffebach , I changed the column X to IID in B. then you command worked.
but I am wondering how can I check that values in column “IID” of A are same as values in X column of B

You can check if Set(A.IID) == Set(B.IID)

thank you for helping me today :grinning: