简体   繁体   中英

Delete rows with duplicated record in two different columns

I would like to delete rows which contain the same string in collumn C1 and C3 :

My df input:

C1       C2      C3
14-130n  NE03   14-130n
23-401n  NE05   21-130n
43-123n  NE04   43-121n

My final expected output:

C1       C2      C3
23-401n  NE05   21-130n
43-123n  NE04   43-121n

I had tried final <- df[!(df[,1] = df[,3]),] , but do not works. Some ideas? Cheers!

For example:

df[!df$C1==df$C3,]

Where df:

df <- read.table(text='C1       C2      C3
14-130n  NE03   14-130n
23-401n  NE05   21-130n
43-123n  NE04   43-121n',header=TRUE,stringsAsFactors=FALSE)

In case you have factors you should coerce to character before:

 df[as.character(df$C1)!=as.character(df$C3),]

final <- subset(df, C1!=C3)可以达到目的?

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