我想生成一个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
欢迎任何技巧!
答案 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)