spore234 spore234 - 1 year ago 106
R Question

translate data frame of observations into ranks

I have a data set like this:

df <- data.frame(situation1=rnorm(30),
models=c(rep("A",10), rep("B",10), rep("C", 10)))

where I compare three models (A,B,C) in three situations. I have 10 measurements for each model.

I now want to summarise this into ranks, i.e. how often each models wins in each situtation. Win is defined by the highest value.

A final output could be something like this:

model situation1 situtation2 situtation3
A 4 3 3
B 7 1 2
C 1 4 5

Answer Source

In base R:

#    situation1 situation2 situation3
#  A          2          4          4
#  B          4          5          1
#  C          2          4          4

Results may change from your OP, since you didn't set a seed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download