-1

Say I have two tables, Table A and Table B, and I want to compare a certain column.

For example,

Table A has the columns:

Name,Surname ,Family, species

Table B has the columns:

IP,Genes,Types,Species,Models

How do I compare the Species column between the two tables to get the matches , that means that i want to extract name of species that exist in both tables?

for exemple if the first species column have

a b c d e f g h i

information and the second species colum have

k l m n a b y i l

i want this result :

a b i

Can you tell me please the way i can do that , and also if there s anyway i can do it without usin join

Thank you very much

Phil
  • 7,287
  • 3
  • 36
  • 66
Reda
  • 449
  • 1
  • 4
  • 17
  • 1
    A [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) would help, as well as some formatting to make what you want clearer. Also, try to polish the English in your question. – Érico Patto Nov 23 '20 at 13:40

1 Answers1

0

Try any of these options. I have used dummy data:

#Data
TableA <- data.frame(Species=c('a','b','c','d','e','f','g','h','i'),
                     Var=1,stringsAsFactors = F)
TableB <- data.frame(Species=c('k','l','m','n','a','b','y','i','l'),
                     Var2=2,stringsAsFactors = F)
#Option1
TableA$Species[TableA$Species %in% TableB$Species]
#Option 2
intersect(TableA$Species,TableB$Species)

In both cases the output will be:

[1] "a" "b" "i"
Duck
  • 39,058
  • 13
  • 42
  • 84
  • Hello , Thank you for you answer , in fact in species columns i have more than 500 lines , so i can't write the information of each line as you did ( 'a','b','c','d','e','f','g','h','i') it was just a exemple to clearify the result i want , thank you – Reda Nov 23 '20 at 13:45
  • @James Always a pleasure, let me know if you have any doubt. I hope the code was useful for you! – Duck Nov 23 '20 at 13:46
  • yes , thank you , but if there's any other way i can do it , because i can't write all the names of all the lines – Reda Nov 23 '20 at 13:49
  • @James You dont need to write in that way. That is only an example. You can directly take the variables stored in your data. I used that example as you didnt share data. Consider only the lines starting in `#Option1`. Let me know if that is clear now! – Duck Nov 23 '20 at 13:52