So I have a kindda odd scenario that I cannot get my head arround:
I have a outerlist which contains multiple innerlists.
Each innerlist contains multiple DataPoint objects.
Every innerlist contains the same amount of DataPoint objects.
A datapoint has a field called Value which is a double - e.g.:
- Outerlist
- Innerlist
- DataPoint(value=2)
- DataPoint(value=2)
- Innerlist
- DataPoint(value=4)
- DataPoint(value=5)
- Innerlist
- DataPoint(value=3)
- DataPoint(value=5)
- Innerlist
So what I wanna do is to "combine" the innerlists into one List where the value of each DataPoint should be the average of the old values, based on its index in the list - in this case:
- List
- DataPoint(3) - ((2+4+3)/3) = 3
- DataPoint(4) - ((2+5+5)/3) = 4
Is there any neat linq expression that could perform this kind of stuff (Im betting there are :))?
I ended up using the following solution:
var averages = Enumerable.Range(0, outer.First().Count()).Select(i => new DataPoint(outer.Select(l => l[i]).Average(x=>x.Value)));
which outputs IEnumerable, now with average valus - yay!