subset a column in data frame based on another data frame/list

We can use %in% to get a logical vector and subset the rows of the ‘table1’ based on that.

subset(table1, gene_ID %in% accessions40$V1)

A better option would be data.table

library(data.table)
setDT(table1)[gene_ID %chin% accessions40$V1]

Or use filter from dplyr

library(dplyr)
table1 %>%
      filter(gene_ID %in% accessions40$V1)

Leave a Comment