r - Removing rows based on column in another dataframe -


this question has answer here:

is there way remove rows dataframe, based on column of dataframe?

for example, dataframe 1:

        gene chrom    pos ref alt n_informative     test       beta       se aaa     1  15211   t   g          1481  1:15211 -0.0599805 0.112445 lll     1 762061   t            1481 1:762061  0.2144100 0.427085 ccc     1 762109   c   t          1481 1:762109  0.2847510 0.204255 ddd     1 762273   g            1481 1:762273  0.0443946 0.119924 

dataframe 2 (only 1 column):

genes aaa bbb ccc ddd eee fff 

in situtation, want scan dataframe 1, column 1 matches dataframe 2, , remove matching rows.

they need exact match, , result this:

        gene chrom    pos ref alt n_informative     test       beta       se lll     1 762061   t            1481 1:762061  0.2144100 0.427085 

i've tried variations of this, hasn't worked:

newdataframe <-!(dataframe1$gene==dataframe2$genes) 

thanks reading.

use %in% identify elements first data frame not contained in second data frame, pass resulting logical vector first data frame subset.

dat1 <- data.frame(id = letters[1:10], stringsasfactors = false) dat2 <- data.frame(id = c("b", "d"), stringsasfactors = false) dat1[!dat1$id %in% dat2$id, , drop = false] #    id # 1   # 3   c # 5   e # 6   f # 7   g # 8   h # 9   # 10  j 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -