How to sort table according to id [duplicate]
You can use arrange
from dplyr
library(dplyr)
Test %>%
arrange(id)
base R
Test[with(Test, order(id)), ]
Output
id date Category coeff PV
1 1 2021-06-30 FDE 4 1
2 1 1975-02-25 ABC 1 4
3 2 2021-07-01 FDE 6 3
4 5 2021-06-30 ABC 1 2
Or if you are wanting to arrange by all columns, then you could add in the additional variables:
Test %>%
arrange(id, date, Category, coeff, PV)
Output
id date Category coeff PV
1 1 1975-02-25 ABC 1 4
2 1 2021-06-30 FDE 4 1
3 2 2021-07-01 FDE 6 3
4 5 2021-06-30 ABC 1 2