0

I have this table x and y like this

x y
0.6 0.2
0.8 0.2
0.2 0.2
0.4 0.2
0.6 0.4
0.8 0.4
0.2 0.4
0.4 0.4
0.6 0.8
0.8 0.8
0.2 0.8
0.4 0.8
0.6 0.6
0.8 0.6
0.2 0.6
0.4 0.6
  • The question is how to order the table using r to be like below?
x y
0.2 0.2
0.2 0.4
0.4 0.2
0.4 0.4
0.4 0.6
0.6 0.4
0.6 0.6
0.6 0.8
0.8 0.6
0.8 0.8

if somebody knows please,

  • I tried to use the command order but it just order in two ways increasing and decreasing.
A H
  • 1
  • 2
  • Please provide more detail in how you want them to be ordered, it is not clear. And also provide code to recreate your dataset – jpsmith Dec 07 '21 at 15:49
  • 1
    @jpsmith you can use `datapasta::tribble_construct` to recreate the dataset – danlooo Dec 07 '21 at 15:59
  • You can use `dplyr::arrange(data,x)` to sort by ascending values of x. However, your example output has 2 rows in which x is 0.2, but your input has 4 rows. Do you want to do some filtering of rows as well? – danlooo Dec 07 '21 at 16:00
  • 2
    *"I tried to use the command order but it just order in two ways increasing and decreasing."* It looks like you want it increasing, first by x then by y??? `data[order(data$x, data$y), ]`. – Gregor Thomas Dec 07 '21 at 16:04
  • @danlooo Hi, I need to be ordered like the second table in which x and y start with the smallest point 0.2 then use the second point 0.4 which will be 0.2 and 0.4 then 0.4 and 0.2 then when x and y are 0.4. After that, when x and y are 0.4 then use the third point 0.6 which will be 0.4 and 0.6 then 0.6 and 0.4 then when x and y are 0.6... – A H Dec 07 '21 at 19:24

0 Answers0