简体   繁体   中英

Removing row with duplicated values in all columns of a data frame (R)

With the following data frame:

d <- structure(list(n = c(2, 3, 5), s = c(2, 8, 3),t = c(2, 18, 30)), .Names = c("n", "s","t"), row.names = c(NA, -3L), class = "data.frame")

which looks like:

> d
  n s  t
1 2 2  2
2 3 8 18
3 5 3 30

How can I remove row with duplicated values in all column. Yielding:

  n s  t
2 3 8 18
3 5 3 30

Here's one possible approach, which compares all columns to the first

d[rowSums(d == d[,1]) != ncol(d),]
#   n s  t
# 2 3 8 18
# 3 5 3 30

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM