i have a data frame like this:
A B C
1 1 1 0.4519
2 101 1 0.3819
3 201 1 0.3819
4 301 1 0.2819
5 401 1 0.9819
6 501 1 0.6819
it's larger but that's an example.
i want to create a new column called order
which include a number from (1 until nrow(df))
and it increase based on the value of the C
column (1 for smallest value and increase with increasing C
value). and when the values in column C are equal change the ordering criteria to column A
and when the values in column A are equal, change it to column B
.
is this can be done in R in an easy and efficient way?
this can be done using a for loop on the data frame and make some if statement, but it will take to much time to finish. that's why i need a faster alternative if possible
thank you