Home > Blockchain >  Subset common excel rows from two file using $in$ R
Subset common excel rows from two file using $in$ R

Time:02-06

I looking forward jo subset/extract common rows from two excel files.

So far I did this:

fa <- read_excel("E:\\Functional_annotation\\Wild\\Karumbyar_FA.xlsx") #file containing 32K rows
cq <- read_excel("E:\\Functional_annotation\\Wild\\cq_genes.xlsx") #file having 1300 rows
cq <- cq$evm.model.contig_303_pilon_pilon_pilon.1 #to make it a vector
cq_fa <- fa[which(fa[,1] %in% cq),]

It creates cq_fa but it has 0 observations but all the variables present in 'fa'! By the way is there any other good way of doing it? Thanks!

I also did this:

combined <- bind_rows(fa, cq)
duplicate_rows <- unique(combined[duplicated(combined), ])

Results same as above.

CodePudding user response:

You can use inner_join.

library(tidyverse)
inner_join(fa, cq)

This assumes the column names in both data frames are identical.

  • Related