Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206209

Count order values in a row, over a column

$
0
0

I have a dataframe with 3 columns: A, B, C In each column there is values going from 0 to 10 I want to figure out how often each possible size orders occurs e.g.:

A>B>C #?
A>C>B #?
B>A>C #?
B>C>A #?
C>A>B #?
C>B>A #?

When dealing with only two columns this is rather easy and can be done as follows:

df$c <- as.numeric(df$a > df$b)

I was wondering whether there is something simlar for 3 or more columns (i.e. a formula that asigns n! values; in the case of n being 3: a 1,2,3,4,5,6 value based on the order observed)


Viewing all articles
Browse latest Browse all 206209

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>