R語(yǔ)言刪除重復(fù)值

R語(yǔ)言刪除重復(fù)值

>test <- data.frame(

? x1 = c(1,2,3,4,5,1,3,5),

? x2 = c("a","b","c","d","e","a","b","e"),

? x3 = c("a","b","c","d","e","a","c","e"))

> test

? x1 x2 x3

1? 1? a? a

2? 2? b? b

3? 3? c? c

4? 4? d? d

5? 5? e? e

6? 1? a? a

7? 3? b? c

8? 5? e? e

> test[!duplicated(test),] #刪掉所有列上都重復(fù)的

? x1 x2 x3

1? 1? a? a

2? 2? b? b

3? 3? c? c

4? 4? d? d

5? 5? e? e

7? 3? b? c

選擇性的刪除重復(fù)的

> test[!duplicated(test[,c(2,3)]),]

? x1 x2 x3

1? 1? a? a

2? 2? b? b

3? 3? c? c

4? 4? d? d

5? 5? e? e

7? 3? b? c

————————————————

版權(quán)聲明:本文為CSDN博主「茁壯小草」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權(quán)協(xié)議,轉(zhuǎn)載請(qǐng)附上原文出處鏈接及本聲明。

原文鏈接:https://blog.csdn.net/xxzhangx/article/details/52369174

示例:setwd("/Users/zhongyue/Desktop/膠囊/07.Venn")

rt=read.table("drug.txt",header=F)

x=rt[!duplicated(rt),]

write.table(x,file="刪減drug.txt",sep="\t",quote=F,row.names=F)#輸出刪減的數(shù)據(jù)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容