2016-07-16 59 views
2

我想生成一個2列data.frame,但我想一定比每個二項式COL1 - col2上是獨一無二的......[R data.frame與非重複二項式

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 

任何訣竅是歡迎!

回答

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) 
+0

謝謝你,但它沒有完成...也許我還沒有指定比我想有1000點意見:-S – delaye