a <- 1:5 b <- letters[1:5] c <- LETTERS[1:5] d <- rep(1,5) dat1 <- data.frame(rbind(a,b,c)) dat2 <- data.frame(rbind(b,c,d)) dat1 dat2 dat3 <- rbind(dat1,dat2) dat3 dup <- dat3[duplicated(dat3),] dup uniq <- dat3[!duplicated(dat3),] uniq
> a <- 1:5 > b <- letters[1:5] > c <- LETTERS[1:5] > d <- rep(1,5) > dat1 <- data.frame(rbind(a,b,c)) > dat2 <- data.frame(rbind(b,c,d)) > dat1 ## 测试数据框1 X1 X2 X3 X4 X5 a 1 2 3 4 5 b a b c d e c A B C D E > dat2 ## 测试数据框2 X1 X2 X3 X4 X5 b a b c d e c A B C D E d 1 1 1 1 1 > dat3 <- rbind(dat1,dat2) ## 按行合并两个测试数据框 > dat3 X1 X2 X3 X4 X5 a 1 2 3 4 5 b a b c d e c A B C D E b1 a b c d e c1 A B C D E d 1 1 1 1 1 > dup <- dat3[duplicated(dat3),] ## 提取重复行 > dup X1 X2 X3 X4 X5 b1 a b c d e c1 A B C D E > uniq <- dat3[!duplicated(dat3),] ## 保留伟一行 > uniq X1 X2 X3 X4 X5 a 1 2 3 4 5 b a b c d e c A B C D E d 1 1 1 1 1