-3

I have two columns x and y. I want to have one column which contains the ranking for both columns. I thought about sum both column and then get it ranked, does any one have a function that rank two columns in r?

Many thanks

aws
  • 15
  • 2
  • 2
    Please share a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and expected output. – markus Sep 04 '18 at 21:54

1 Answers1

0

If you are just wanting to use the rank function as you suggest:

df1 <- data.frame(x = rnorm(10), y = rnorm(10))
apply(df1, 2, rank) # 2 columns with separate rankings
rank(rowSums(df1)) # sum by rows first, then rank
rank(rowMeans(df1)) # avg by rows first, then rank (same result!)
Evan Friedland
  • 3,062
  • 1
  • 11
  • 25