I have the following like data in a tab-delimted text file named original
Name Symbol Value
abcd A 56
de45 C 67
ji98 H 90
k9ug K 43
phzt L 98
prex P 21
kadf T 32
Also I have list of selected Symbols stored in another tab delimited text file named duplicate
Symbol Description
K Intel
P Diary
C Cape
S Sheath
A Aim
I want to extract the rows from original file which has same Symbol with duplicate. I want my output like the following:
Name Symbol Value
abcd A 56
de45 C 67
k9ug K 43
prex P 21
I tried using the following code but some how I could not get any results or only the row of A. Here is the code which I have used
result <- original[original$Symbol %in% duplicate$Symbol,]
Could anyone please help me.
This can be done with a simple
merge:You can manually drop the
Descriptioncolumn before or after merging if it is not relevant.Also, I don’t know if this is a problem with the question as posted or if it is a problem with your code, but:
Of course, you have to spell
originalcorrectly, which you did not!Assumptions
names(original)shows up with an upper-case S (Symbol).names(duplicate)shows up with a lower-case s (symbol).If both are capitalized, then you can use either of the following solutions: