R data.frame具有非重复二项式

时间:2016-07-16 19:49:21

标签: r duplicates unique

我想生成一个2列data.frame,但我想确定每个二项式col1 - col2是唯一的......

n <- 1000
w <- seq(from = 0, to = n-1, by = 1)
x <- sample(0:99, n, replace=T)
y <- sample(0:99, n, replace=T)
input.df <- data.frame(xcor = sample(0:99, n, replace=T), y = sample(0:99, n, replace=T))

此时它显然不起作用

summary(duplicated(input.df))

Mode   FALSE    TRUE    NA's 
logical     972      28       0 

我想要

summary(duplicated(input.df))

Mode   FALSE    TRUE    NA's 
logical     1000      0       0

欢迎任何技巧!

1 个答案:

答案 0 :(得分:2)

你太近了!您只需在括号内使用duplicated并使用!来指定重复。

n <- 1000
w <- seq(from = 0, to = n-1, by = 1)
x <- sample(0:99, n, replace=T)
y <- sample(0:99, n, replace=T)
input.df <- data.frame(xcor = sample(0:99, n, replace=T), y = sample(0:99, n, replace=T))

summary(duplicated(input.df[!duplicated(input.df),]))
   Mode   FALSE    NA's 
logical     958       0

这相当于哲元所提到的unique()

final_data <- input.df[!duplicated(input.df),]

final_data <- unique(input.df)