【问题标题】:find partial match between two data frame找到两个数据框之间的部分匹配
【发布时间】:2025-12-16 14:45:01
【问题描述】:

我有两个数据框。

head(NEexp)
 Gene   Transcript Ratio_log2      FDR
HLHmgamma HLHmgamma-RA   3.759200 1.09e-10
Brd       Brd-RA   3.527000 2.66e-08
CG4080     CG4080-RE   3.378500 2.95e-50
RpII215   RpII215-RA   3.343967 1.82e-10

head(excel$gene)
Enhancer of split mgamma, helix-loop-helix
distal antenna
CG4080 gene product from transcript CG4080-RB

如您所见,这两个基因列部分匹配(HLHmgamma 匹配分裂 mgamma 的增强子,螺旋-环-螺旋;CG4080 匹配来自转录本 CG4080-RB 的 CG4080 基因产物),无论如何我可以将这两者联系起来吗? 到目前为止我尝试过的代码:

genename=as.character(NEexp$Gene)
query=paste("select * from excel where excel.gene LIKE \"", genename,"\ ",sep"")
Newtable<-dbGetQuery(con,query)

dbGetQuery(con,"select * from excel, NEexp where excel.gene LIKE % "NEexp$Gene" %")

【问题讨论】:

    标签: sql r rsqlite


    【解决方案1】:

    您需要 merge ,它与 SQL 中的 join 基本相同。但首先您可能想要拆分 excel$gene 以获得您想要匹配的部分。

    http://stat.ethz.ch/R-manual/R-devel/library/base/html/merge.html

    https://stat.ethz.ch/R-manual/R-devel/library/base/html/strsplit.html

    【讨论】: