For a table as follows, how can I divide these records evenly into 3 groups based on the value of “factor_value”?
sym date factor_value
------ ---------- ------------
100000 2022.04.27 1
100001 2022.04.27 2
100002 2022.04.27 3
100003 2022.04.27 4
100004 2022.04.27 5
100005 2022.04.27 6
100006 2022.04.27 7
100007 2022.04.27 8
100008 2022.04.27 9
100009 2022.04.27 10
100010 2022.04.28
100000 2022.04.28
100001 2022.04.28
100002 2022.04.28 3
100003 2022.04.28 4
100004 2022.04.28 5
100005 2022.04.28 6
100006 2022.04.28 7
100007 2022.04.28 8
100008 2022.04.28 9
This can be implemented by DolphinDB functions
cutPointsandasof.First, use
contexy bywithcsortto sort the column factor_value. Then allocate the records into 3 groups evenly withcutPoints.asofreturns the grouping number for each element in the group.output: