Q:

Complex elementwise comparison by columns in R

I'd like to compare subjects by two column entries: Value and Length. 
The subject will be compared with all other subjects in the data frame; they will receive a -1 for each subject that has a higher value in the 'Length' column. If they have a higher value for the entry in the 'Length' column they will receive a +1. If their value is equal to another subject's value in the 'Length' column, their value in the 'Value' column will be compared (+1 if their entry is greater; 0 if the value is equal; and -1 if their value is less). The entry in the new column 'Value2' would be the sum of the +1, 0, or -1 values from the comparisons.
I have written something in base R but it doesn't seem to work. 
             Value        Length
Subject1     2            0
Subject2     0            1
Subject3     5            1
Subject4     4            5
Subject5     4            5
Subject6     7            6
Subject7     9            8

for(i in 1:length(x)){
   for(j in 1:length(x)){
      if(i != j){
         w = z[c(-i), ]
         if(w$length[i] < w$length[j]){ value2[i] = value2[i] -1   }

         if(w$length[i] > w$length[j]){ value2[i] = value2[i} + 1  }

         if(w$length[i] == w$length[j]){
            if(w$value[i] < w$value[j]){ value2[i] = value2[i] - 1 }
            if(w$value[i] > w$value[j]){ value2[i] = value2[i] + 1 }

            if(w$value[i] == w$value[j]){ value2[i] = value2[i] }
         }
      }
   }
}

Expected output:
            Value        Length      Value2
Subject1     2            0          -6
Subject2     0            1          -4
Subject3     5            1          -2          
Subject4     4            5          +1
Subject5     4            5          +1
Subject6     7            6          +4
Subject7     9            8          +6

A:

Basically, you want to use rank and its tie-breaking but with two instead of one vector as input. The easiest solution would be to combine these two vectors. E.g., if you only have integers, you can do this:
res <- DF$Length + DF$Value/(max(DF$Value) + 1)
#[1] 0.2 1.0 1.5 5.4 5.4 6.7 8.9
res <- rank(res)
#[1] 1.0 2.0 3.0 4.5 4.5 6.0 7.0
res <- c(scale(res * 2, scale = FALSE)) #transformation of ranks
#[1] -6 -4 -2  1  1  4  6

