I have a large data.frame
of bond data, like that:
ISIN CF DATE
A 105.750 2016-09-30
B 104.875 2016-05-31
C 106.875 2017-02-13
D 103.875 2016-10-07
E 5.000 2016-04-21
E 5.000 2017-04-21
E 5.000 2018-04-21
E 5.000 2019-04-21
E 105.000 2020-04-21
F 7.800 2016-09-09
F 7.800 2017-09-09
F 7.800 2018-09-09
F 7.800 2019-09-09
F 107.800 2020-09-09
I want to group the elements by the ISIN
code, then within these groups sort the CF
elements by DATE
in increasing order (already done in the example above). Then I want to sort the groups (A
, B
, C
, D
, E
, F
in this example) such that the group with the earliest date comes first, then the group with the second earliest date, and so on.
I want it to look like this:
ISIN CF DATE
E 5.000 2016-04-21
E 5.000 2017-04-21
E 5.000 2018-04-21
E 5.000 2019-04-21
E 105.000 2020-04-21
B 104.875 2016-05-31
F 7.800 2016-09-09
F 7.800 2017-09-09
F 7.800 2018-09-09
F 7.800 2019-09-09
F 107.800 2020-09-09
A 105.750 2016-09-30
D 103.875 2016-10-07
C 106.875 2017-02-13
I tried something like from this question:
df<-df[order(df$ISIN,df$DATE),]
But it doesn't do what I want.