简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM