This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Merge two tables based on two columns (R)

Dear all,

trivial question. i have two tables that i would like to merge based on two columns. Basically i would like to translate to R what here i write in bash.

1st table (file a)

a   Solyc11g071810
a   Solyc11g071811
a   Solyc11g071812
a   Solyc11g071813
a   Solyc11g071814

2nd table (file b)

a   Solyc11g071810  low
a   Solyc11g071811  high
a   Solyc11g071812  medium
a   Solyc11g071813  very low
a   Solyc11g071814  medium
a   Solyc11g071819  very low
b   Solyc11g071813  high

Expected result (file c):

a   Solyc11g071810  low
a   Solyc11g071811  high
a   Solyc11g071812  medium
a   Solyc11g071813  very low
a   Solyc11g071814  medium

bash code:

cat a  | grep -w -F -f - b > c

thanks in advance for any help

r

Benn, please do not close posts that already have answers. It's a practice agreed to on the moderator slack channel. - @RamRS

Hello lessismore!

We believe that this post does not fit the main topic of this site.

Not bioinformatics. For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

1 answer

Please search online and do some homework before you ask us to help you. See the first result when you google "r merge by two columns".

You can use by = c('col1','col2') in merge to get to your result.

Log in to answer this question.