刪除R中具有重復屬性的行 - Get rid of rows with duplicate attributes in R -开发者知识库

刪除R中具有重復屬性的行 - Get rid of rows with duplicate attributes in R -开发者知识库,第1张

I have a big dataframe with columns such as:

我有一個大的dataframe,列有如下內容:

ID, time, OS, IP

Each row of that dataframe corresponds to one entry. Within that dataframe for some IDs several entries (rows) exist. I would like to get rid of those multiple rows (obviously the other attributes will differ for the same ID). Or put different: I only want one single entry (row) for each ID.

該數據aframe的每一行對應一個條目。在某些id的dataframe中存在幾個條目(行)。我想刪除這些多行(顯然,對於相同的ID,其他屬性會有所不同)。或者設置不同:我只希望每個ID有一個條目(行)。

When I use unique on the ID column, I only receive the levels (or each unique ID), but I want to keep the other attributes as well. I have tried to use apply(x,2,unique(data$ID)), but this does not work either.

當我在ID列上使用unique時,我只接收級別(或每個惟一ID),但我也希望保留其他屬性。我嘗試過使用apply(x,2,unique(data$ID)),但這也不管用。

2 个解决方案

#1


26  

subset(data,!duplicated(data$ID))

Should do the trick

應該足夠了

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复