I need to identify pairs of variables that are dominated: if both values of the pair are lower than the other pairs in the data.
I already tried the functions min
or pmin
but I am not sure if they are the most appropriate.
a = matrix(c(50,70), ncol = 2)
b = matrix(c(45,85), ncol = 2)
df = rbind(a,b)
Dominance <- function(a){
for (i in 1:nrow(a)) {
for (j in 1:nrow(a)) {
i1 <- rowSums(a[i,] < a[j,]) == ncol(a)
a[i1,, drop = FALSE]
}
}
return(a)
}
l = Dominance(df)
> l
X1 X2
1 45 65
2 50 70
I expect the pair (45,65) to be removed.