How to remove rows from a data frame when the column matches with a different data frame column in R

StackOverflow https://stackoverflow.com/questions/22441133

  •  15-06-2023
  •  | 
  •  

Question

I have a data frame A of the below format Word Freq p 9531 can 2085 /p 2055 get 1183 use 1112

and another data frame B

Word Freq p 10 can 2 /p 55

Now I want to remove the rows from data frame A that has a matching in the data frame B. So my output would be for data frame A

Word Freq get 1183 use 1112

Was it helpful?

Solution

Do it this way:

A<-read.table(text="Word     Freq
p        9531
can      2085
/p       2055
get      1183
use      1112",header=T)

B<-read.table(text="Word     Freq
p        10
can      2
/p       55",header=T)

A[-which(A$Word %in% B$Word),]

result:

  Word Freq
4  get 1183
5  use 1112
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top