group by average on a list of objects in C# -
i have list of objects object looks below
public class sample { public datetime _dt; public decimal _d; public decimal_value; }
i want list grouped year , month of date , _d values _value averaged.
so if month jan, list has
one set of 31 values _d =1, 1 set of 31 values _d =5
result list of sample have 2 values
1/1/2016 ,_d = 1 , average of _value 1/1/2016 ,_d = 5 , average of _value
initially have redefine sample
class.
public class sample { public datetime _dt { get; set; } public decimal _d { get; set; } public decimal _value { get; set; } }
if have list of sample
objects called samples
, want:
var results = samples.groupby(sample => { year = _dt.year, month = _dt.month dvalue = _d}) .select(gr => new { year = gr.key.year, month = gr.key.month, dvalue = gr.key.dvalue, averagevalue = gr.select(item => item.value).average() });
Comments
Post a Comment