Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing data from one dataframe that exists in another dataframe R

Tags:

r

I want to remove data from a dataframe that is present in another dataframe. Let me give an example:

letters<-c('a','b','c','d','e')
numbers<-c(1,2,3,4,5)
list_one<-data.frame(letters,numbers)

I want to remove every row in list_one with matches in letters to this other dataframe:

letters2<-c('a','c','d')
list_two<-data.frame(letters2)

I should mention that I'm actually trying to do this with two large csv files, so I really can't use the negative expression - to take out the rows.

And create a final dataframe which only has the letters b and e and their corresponding numbers. How do I do this?

I'm new to R so it's hard to research questions when I'm not quite sure what key terms to search. Any help is appreciated, thanks!

like image 801
kevluv93 Avatar asked Oct 13 '15 20:10

kevluv93


1 Answers

A dplyr solution

library(dplyr)

list_one %>% anti_join(list_two)
like image 177
bramtayl Avatar answered Oct 13 '22 02:10

bramtayl