0

I have what I believe a simple question, however, I haven't figured out how to solve it. I want to order values like in the example:

x <- data.frame(X=c(10:1), L=c("A","B","C","C","A","B","C","A","B","C"))
x
    X L
1  10 A
2   9 B
3   8 C
4   7 C
5   6 A
6   5 B
7   4 C
8   3 A
9   2 B
10  1 C

to

    X L
1   3 A
2   6 A
3  10 A
4   2 B
5   5 B
6   9 B
7   1 C
8   4 C
9   7 C
10  8 C

So as you see, basically, I want to order one column (alphabetical order), then, within each value in that column ordered, order the rows according to the numbers. (The real data frame is large)

I'm pretty sure it is with the order() function, but I just don't know how to order within the data frame for each value.

Thanks

akrun
  • 789,025
  • 32
  • 460
  • 575
rlsrls
  • 51
  • 3

0 Answers0