I am working with a set of 5 excel columns A,B,C,D,E
of words "Aaa","Aab"...
and I want to find the exact matches in all the columns (in R).
A B C D E
Aaa Aaa Baa Aaa Ass
Aab Ccc Aaa Baa Aaa
Ccc Abc Ccc Ccc Ccc
... ... ... ... ...
I create a vector for each column.
For that I have try a for
loop with if
and grep
function.
<pre>
for(i in A_vector) {
if(grep("i", B_vector))
if(grep("i", C_vector))
if(grep("i", D_vector))
if(grep("i", E_vector))
print(i)
}
<code>
(but I only obtain the words in the first vector A_vector
).
At the end I would like to have a vector with the words "Aaa", "Bbb"...
that match in the 5 columns. I do not need the position of each match within the vector, just the words that are common to all the vectors.
Result
[1] "Aaa"
[2] "Ccc"
[n] ...
Thank you in advance!