Entering edit mode
5.4 years ago
aksoyluinci
▴
10
Hello all!
I have two data frames as the first one contains gene names (511 lines) and a single column and the second one contains Chromosome,Position,Rsid,Ref,ALT....Gene
(187th column) and so on.
I want to compare these two dataframes and keep the rows in second dataframe based on "Gene" column. How can I do this in RStudio?
for example:
df1:
AARD
NOC2L
EPHA10
df2:
info.. info.. info... SAMD11
info.. info.. info.. NOC2L
info.. info.. info.. EPHA10
info.. info.. info.. AARD
new dataframe as output(the one I want):
info.. info.. info.. NOC2L
info.. info.. info.. EPHA10
info.. info.. info.. AARD
Thanks!
What have you tried? This seems like a quite basic R subsetting/dataframe slicing question, of which you can find plenty of solutions online.
Well,i tried several methods,though i couldnt extract the whole row in dataframe 2, instead i could extract the names only + when i used the intersect function it gave me error since these datasets are not same in size.
Please share the code even if it is not working, that would help us to understand the problem.
And, this is a basic R question, more suitable at StackOverflow, just
merge
common gene columns, see:Or use
%in%
:If it is single field matching, you can use join in *nix