0

I have a query which returns a count of objects grouped by these objects in a table although what I want to do afterwards is to firstly sort the values from highest to lowest and the partition them into 10 groups.

What I have so far allows me to either sort the counted values from max to min or, if i comment the sort out, or partition the values by a set number. I would like to know where Im going wrong here because I cant see it. I am pulling the count of objects from the query initially, sorting and then trying to partition them into arrays which I will index at a later stage:

tosort(map(keyword :objectscounted)data)
sorted(sort > tosort)
part(into [] (partition-all 10 sorted))

Where I am also stuck is when using the partition - I need 10 groups of values, not 10 values in each group, any help here is appreciated! Thanks in advance

1 Answer 1

1

If I understood correctly your problem, all you need is to partition dynamically according to your sorted list element count:

user> (def v (range 50))
#'user/v
user> (clojure.pprint/pprint (partition-all (/ (count v) 10) v))
((0 1 2 3 4)
 (5 6 7 8 9)
 (10 11 12 13 14)
 (15 16 17 18 19)
 (20 21 22 23 24)
 (25 26 27 28 29)
 (30 31 32 33 34)
 (35 36 37 38 39)
 (40 41 42 43 44)
 (45 46 47 48 49))

Of course if total elements is not divisible by 10, your result will have have more than 10 groups, unless you have a different strategy to distribute elements among groups.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.