*less than*400 or there are 11 groups. In my example I'll use a maximum value smaller than 400, but it's easy to adjust if you want 11 groups or if you want to e.g. include 400 in the last group.

You could do something like this:

Dim array = New Decimal() {10, 20, 30, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390} Dim groups = New List(Of IEnumerable(Of Decimal)) For index As Integer = 0 To 9 Dim lowerBound = index / 10 * 400 Dim upperBound = (index + 1) / 10 * 400 groups.Add(array.Where(Function(n) (n >= lowerBound And n < upperBound))) Next Dim averages = groups.Select(Function(g) If(g.Count > 0, g.Average(), -1))

"array" holds a number of values with min 0 and max <400.

"groups" holds groups with values 0 to 40, 40 to 80 etc.

"averages" holds the average of each of these groups, or -1 if the group is empty.

If you don't care about the empty groups (40-80 in my code example), you could do this more elegantly:

```
Dim groups = array.GroupBy(Function(n) Math.Floor(n / 40))
Dim averages = groups.Select(Function(g) g.Average())
```

To give this a little bit more sense and context, I am trying to summarize a datalog from a car, each "frame" or "entry" comes with a RPM value , which of course varies from 0 to 8000, i get thousands of those records and I need to represent them in a rpm table and the amount of hits each "fixed" index has received.

In a practical example, lets assume we got the following values to process

{10,50,90,50,10,400,450,300,550,900,950,1100,1200,1000,900}

rpm | hits

-----|---------

100 | 5 hits

500 | 4 hits

1000 | 6 hits

In this example I have kind of grouped similar numbers for the sake of simplicity, I do know how to calculate the hits, and to find out to which "index" each value should go, but what i need to find out first is what are the best indexes for the table.

I have created those 3 indexes (100,500,1000) fixed, but I don't know if those are the best indexes to split my numbers, it might be 500 or 400 or 474, who knows.

That is the situation i am debating on how to be done, how do you find the best indexes, which can even vary, they could be just 3 or could be 10 or N , the user will have the input to "subdivide" the indexes in the amount they wish.

Hope it is making a little bit more of sense now.

I'd strongly suggest to ask car provider.