library(stringr)
df <- unique(df)
#paste rows omitting NAs
df$new <- apply(df, 1, function(i) paste(na.omit(i), collapse = ''))
#use str_detect to determine whether each pattern is found more than once
df$new2 <- rowSums(sapply(df$new, function(i) str_detect(i, df$new)))
new_df <- subset(df, df$new2 == 1)
new_df <- new_df[, !names(new_df) %in% c('new', 'new2')]
new_df
# V2 V3 V4 V5
#2 2 1 3 3
#3 2 1 4 3
#4 2 2 3 NA
根据您的评论,使用附加行测试代码:
new_df
# a1 a2 a3 a4
#c2 2 1 3 3
#c3 2 1 4 3
#c4 2 2 3 NA
#c7 2 NA 0 NA
DATA
dput(df)
structure(list(a1 = c(2L, 2L, 2L, 2L, 2L, 2L, 2L), a2 = c(1L,
1L, 1L, 2L, 1L, NA, NA), a3 = c(3L, 3L, 4L, 3L, 3L, 3L, 0L),
a4 = c(NA, 3L, 3L, NA, 3L, NA, NA)), .Names = c("a1", "a2",
"a3", "a4"), class = "data.frame", row.names = c("c1", "c2",
"c3", "c4", "c5", "c6", "c7"))